├── Stb.cs ├── Str.cs ├── Util.cs └── stbchecker.sln /Stb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | public class StbTable 6 | { 7 | List tagList; 8 | public string[] TagList 9 | { 10 | get 11 | { 12 | return tagList.ToArray(); 13 | } 14 | } 15 | 16 | string name; 17 | public string Name 18 | { 19 | get { return name; } 20 | } 21 | 22 | string str; 23 | public string String 24 | { 25 | get { return str; } 26 | } 27 | 28 | public StbTable(string name, string str) 29 | { 30 | this.name = name; 31 | this.str = str; 32 | 33 | tagList = ParseTagList(str); 34 | } 35 | 36 | public static string UnescapeStr(string str) 37 | { 38 | int i, len; 39 | string tmp; 40 | 41 | len = str.Length; 42 | tmp = ""; 43 | 44 | for (i = 0; i < len; i++) 45 | { 46 | if (str[i] == '\\') 47 | { 48 | i++; 49 | switch (str[i]) 50 | { 51 | case '\\': 52 | tmp += '\\'; 53 | break; 54 | 55 | case ' ': 56 | tmp += ' '; 57 | break; 58 | 59 | case 'n': 60 | case 'N': 61 | tmp += '\n'; 62 | break; 63 | 64 | case 'r': 65 | case 'R': 66 | tmp += '\r'; 67 | break; 68 | 69 | case 't': 70 | case 'T': 71 | tmp += '\t'; 72 | break; 73 | } 74 | } 75 | else 76 | { 77 | tmp += str[i]; 78 | } 79 | } 80 | 81 | return tmp; 82 | } 83 | 84 | public static StbTable ParseTableLine(string line, ref string prefix) 85 | { 86 | int i, len; 87 | int string_start; 88 | int len_name; 89 | string name, name2; 90 | 91 | line = line.TrimStart(' ', '\t'); 92 | len = line.Length; 93 | if (len == 0) 94 | { 95 | return null; 96 | } 97 | 98 | if (line[0] == '#' || (line[0] == '/' && line[1] == '/')) 99 | { 100 | return null; 101 | } 102 | 103 | bool b = false; 104 | len_name = 0; 105 | for (i = 0; i < line.Length; i++) 106 | { 107 | if (line[i] == ' ' || line[i] == '\t') 108 | { 109 | b = true; 110 | break; 111 | } 112 | len_name++; 113 | } 114 | 115 | if (b == false) 116 | { 117 | return null; 118 | } 119 | 120 | name = line.Substring(0, len_name); 121 | 122 | string_start = len_name; 123 | for (i = len_name; i < len; i++) 124 | { 125 | if (line[i] != ' ' && line[i] != '\t') 126 | { 127 | break; 128 | } 129 | string_start++; 130 | } 131 | if (i == len) 132 | { 133 | return null; 134 | } 135 | 136 | string str = line.Substring(string_start); 137 | 138 | str = UnescapeStr(str); 139 | 140 | if (Str.StrCmpi(name, "PREFIX")) 141 | { 142 | prefix = str; 143 | prefix = prefix.TrimStart(); 144 | 145 | if (Str.StrCmpi(prefix, "$") || Str.StrCmpi(prefix, "NULL")) 146 | { 147 | prefix = ""; 148 | } 149 | 150 | return null; 151 | } 152 | 153 | name2 = ""; 154 | 155 | if (prefix != "") 156 | { 157 | name2 += prefix + "@"; 158 | } 159 | 160 | name2 += name; 161 | 162 | return new StbTable(name2, str); 163 | } 164 | 165 | public static bool CompareTagList(string[] list1, string[] list2) 166 | { 167 | if (list1.Length != list2.Length) 168 | { 169 | return false; 170 | } 171 | 172 | int i; 173 | for (i = 0; i < list1.Length; i++) 174 | { 175 | if (list1[i] != list2[i]) 176 | { 177 | return false; 178 | } 179 | } 180 | 181 | return true; 182 | } 183 | 184 | public static List ParseTagList(string str) 185 | { 186 | List list = new List(); 187 | int i, len; 188 | int mode = 0; 189 | string tmp = ""; 190 | 191 | str += "_"; 192 | 193 | len = str.Length; 194 | 195 | for (i = 0; i < len; i++) 196 | { 197 | char c = str[i]; 198 | 199 | if (mode == 0) 200 | { 201 | switch (c) 202 | { 203 | case '%': 204 | if (str[i + 1] == '%') 205 | { 206 | i++; 207 | tmp += c; 208 | } 209 | else 210 | { 211 | mode = 1; 212 | tmp = "" + c; 213 | } 214 | break; 215 | 216 | default: 217 | tmp = "" + c; 218 | break; 219 | } 220 | } 221 | else 222 | { 223 | string tag; 224 | 225 | switch (c) 226 | { 227 | case 'c': 228 | case 'C': 229 | case 'd': 230 | case 'i': 231 | case 'o': 232 | case 'u': 233 | case 'x': 234 | case 'X': 235 | case 'e': 236 | case 'E': 237 | case 'f': 238 | case 'g': 239 | case 'G': 240 | case 'n': 241 | case 'N': 242 | case 's': 243 | case 'S': 244 | case 'r': 245 | case ' ': 246 | tmp += c; 247 | tag = tmp; 248 | list.Add(tag); 249 | mode = 0; 250 | break; 251 | default: 252 | tmp += c; 253 | break; 254 | } 255 | } 256 | } 257 | 258 | return list; 259 | } 260 | } 261 | 262 | public class Stb 263 | { 264 | Dictionary tableList; 265 | string name; 266 | public string Name 267 | { 268 | get { return name; } 269 | } 270 | 271 | public Stb(string fileName) 272 | { 273 | init(File.ReadAllBytes(fileName), fileName); 274 | } 275 | 276 | public Stb(string fileName, string name) 277 | { 278 | init(File.ReadAllBytes(fileName), name); 279 | } 280 | 281 | public Stb(byte[] data, string name) 282 | { 283 | init(data, name); 284 | } 285 | 286 | void init(byte[] data, string name) 287 | { 288 | if (data[0] == 0xef && data[1] == 0xbb && data[2] == 0xbf) 289 | { 290 | byte[] tmp = new byte[data.Length - 3]; 291 | Array.Copy(data, 3, tmp, 0, data.Length - 3); 292 | data = tmp; 293 | } 294 | 295 | StringReader sr = new StringReader(Str.Utf8Encoding.GetString(data)); 296 | tableList = new Dictionary(); 297 | 298 | this.name = name; 299 | string prefix = ""; 300 | 301 | while (true) 302 | { 303 | string tmp = sr.ReadLine(); 304 | if (tmp == null) 305 | { 306 | break; 307 | } 308 | 309 | StbTable t = StbTable.ParseTableLine(tmp, ref prefix); 310 | if (t != null) 311 | { 312 | if (tableList.ContainsKey(t.Name.ToUpper()) == false) 313 | { 314 | tableList.Add(t.Name.ToUpper(), t); 315 | } 316 | else 317 | { 318 | ShowWarning(name, string.Format("Duplicated '{0}'", t.Name)); 319 | } 320 | } 321 | } 322 | } 323 | 324 | protected static void ShowWarning(string name, string str) 325 | { 326 | Console.WriteLine("{0}: Warning: {1}", name, str); 327 | } 328 | 329 | protected static void ShowError(string name, string str) 330 | { 331 | Console.WriteLine("{0}: Error: {1}", name, str); 332 | } 333 | 334 | public static int Compare(string file1, string file2) 335 | { 336 | Stb stb1 = new Stb(file1, "File1"); 337 | Stb stb2 = new Stb(file2, "File2"); 338 | int num = 0; 339 | 340 | string file1_fn = Path.GetFileName(file1); 341 | string file2_fn = Path.GetFileName(file2); 342 | 343 | foreach (string name1 in stb1.tableList.Keys) 344 | { 345 | if (name1.Equals("DEFAULT_FONT_WIN7", StringComparison.InvariantCultureIgnoreCase) || 346 | name1.Equals("DEFAULT_FONT_HIGHDPI", StringComparison.InvariantCultureIgnoreCase)) 347 | { 348 | continue; 349 | } 350 | 351 | StbTable t1 = stb1.tableList[name1]; 352 | 353 | if (stb2.tableList.ContainsKey(name1) == false) 354 | { 355 | ShowError(stb2.name, string.Format("Missing '{0}'", t1.Name)); 356 | num++; 357 | } 358 | else 359 | { 360 | StbTable t2 = stb2.tableList[name1]; 361 | 362 | if (StbTable.CompareTagList(t1.TagList, t2.TagList) == false) 363 | { 364 | ShowError(stb2.name, string.Format("Difference printf-style parameters '{0}'", t1.Name)); 365 | num++; 366 | } 367 | } 368 | } 369 | 370 | Console.WriteLine("\nThere are {0} errors.\n\n{1}\n", num, 371 | (num == 0 ? "Good work! No problem!" : "You must correct them before sending us Pull Requests!")); 372 | 373 | return num; 374 | } 375 | } 376 | -------------------------------------------------------------------------------- /Str.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | 6 | public class Str 7 | { 8 | static Encoding asciiEncoding = Encoding.ASCII; 9 | public static Encoding AsciiEncoding 10 | { 11 | get { return Str.asciiEncoding; } 12 | } 13 | 14 | static Encoding utf8Encoding = Encoding.UTF8; 15 | public static Encoding Utf8Encoding 16 | { 17 | get { return Str.utf8Encoding; } 18 | } 19 | 20 | static Encoding uniEncoding = Encoding.Unicode; 21 | public static Encoding UniEncoding 22 | { 23 | get { return Str.uniEncoding; } 24 | } 25 | 26 | public static string ByteToHex3(byte[] data) 27 | { 28 | if (data.Length == 0) 29 | { 30 | return ""; 31 | } 32 | 33 | return BitConverter.ToString(data) + "-"; 34 | } 35 | 36 | public static string ByteToHex(byte[] data) 37 | { 38 | StringBuilder ret = new StringBuilder(); 39 | foreach (byte b in data) 40 | { 41 | string s = b.ToString("X"); 42 | if (s.Length == 1) 43 | { 44 | s = "0" + s; 45 | } 46 | 47 | ret.Append(s); 48 | } 49 | 50 | return ret.ToString(); 51 | } 52 | 53 | public static byte[] HexToByte(string str) 54 | { 55 | try 56 | { 57 | List o = new List(); 58 | string tmp = ""; 59 | int i, len; 60 | 61 | str = str.ToUpper().Trim(); 62 | len = str.Length; 63 | 64 | for (i = 0; i < len; i++) 65 | { 66 | char c = str[i]; 67 | if (('0' <= c && c <= '9') || ('A' <= c && c <= 'F')) 68 | { 69 | tmp += c; 70 | if (tmp.Length == 2) 71 | { 72 | byte b = Convert.ToByte(tmp, 16); 73 | o.Add(b); 74 | tmp = ""; 75 | } 76 | } 77 | else if (c == ' ' || c == ',' || c == '-' || c == ';') 78 | { 79 | } 80 | else 81 | { 82 | break; 83 | } 84 | } 85 | 86 | return o.ToArray(); 87 | } 88 | catch 89 | { 90 | return new byte[0]; 91 | } 92 | } 93 | 94 | public static string ByteToStr(byte[] data, Encoding enc) 95 | { 96 | try 97 | { 98 | return enc.GetString(data); 99 | } 100 | catch 101 | { 102 | return ""; 103 | } 104 | } 105 | 106 | public static byte[] StrToByte(string str, Encoding enc) 107 | { 108 | try 109 | { 110 | return enc.GetBytes(str); 111 | } 112 | catch 113 | { 114 | return new byte[0]; 115 | } 116 | } 117 | 118 | public static string[] GetLines(string str) 119 | { 120 | List a = new List(); 121 | StringReader sr = new StringReader(str); 122 | while (true) 123 | { 124 | string s = sr.ReadLine(); 125 | if (s == null) 126 | { 127 | break; 128 | } 129 | a.Add(s); 130 | } 131 | return a.ToArray(); 132 | } 133 | 134 | public static string LinesToStr(string[] lines) 135 | { 136 | StringWriter sw = new StringWriter(); 137 | foreach (string s in lines) 138 | { 139 | sw.WriteLine(s); 140 | } 141 | return sw.ToString(); 142 | } 143 | 144 | public static bool IsEmptyStr(string str) 145 | { 146 | if (str == null || str.Trim().Length == 0) 147 | { 148 | return true; 149 | } 150 | else 151 | { 152 | return false; 153 | } 154 | } 155 | 156 | public static bool IsSplitChar(char c, string splitStr) 157 | { 158 | if (splitStr == null) 159 | { 160 | splitStr = StrToken.DefaultSplitStr; 161 | } 162 | 163 | foreach (char t in splitStr) 164 | { 165 | string a = "" + t; 166 | string b = "" + c; 167 | if (Util.StrCmpi(a, b)) 168 | { 169 | return true; 170 | } 171 | } 172 | 173 | return false; 174 | } 175 | 176 | public static bool GetKeyAndValue(string str, out string key, out string value) 177 | { 178 | return GetKeyAndValue(str, out key, out value, null); 179 | } 180 | public static bool GetKeyAndValue(string str, out string key, out string value, string splitStr) 181 | { 182 | uint mode = 0; 183 | string keystr = "", valuestr = ""; 184 | if (splitStr == null) 185 | { 186 | splitStr = StrToken.DefaultSplitStr; 187 | } 188 | 189 | foreach (char c in str) 190 | { 191 | switch (mode) 192 | { 193 | case 0: 194 | if (IsSplitChar(c, splitStr) == false) 195 | { 196 | mode = 1; 197 | keystr += c; 198 | } 199 | break; 200 | 201 | case 1: 202 | if (IsSplitChar(c, splitStr) == false) 203 | { 204 | keystr += c; 205 | } 206 | else 207 | { 208 | mode = 2; 209 | } 210 | break; 211 | 212 | case 2: 213 | if (IsSplitChar(c, splitStr) == false) 214 | { 215 | mode = 3; 216 | valuestr += c; 217 | } 218 | break; 219 | 220 | case 3: 221 | valuestr += c; 222 | break; 223 | } 224 | } 225 | 226 | if (mode == 0) 227 | { 228 | value = ""; 229 | key = ""; 230 | return false; 231 | } 232 | else 233 | { 234 | value = valuestr; 235 | key = keystr; 236 | return true; 237 | } 238 | } 239 | 240 | public static int StrCmpRetInt(string s1, string s2) 241 | { 242 | return s1.CompareTo(s2); 243 | } 244 | public static bool StrCmp(string s1, string s2) 245 | { 246 | return StrCmpRetInt(s1, s2) == 0 ? true : false; 247 | } 248 | public static int StrCmpiRetInt(string s1, string s2) 249 | { 250 | s1 = s1.ToUpper(); 251 | s2 = s2.ToUpper(); 252 | return StrCmpRetInt(s1, s2); 253 | } 254 | public static bool StrCmpi(string s1, string s2) 255 | { 256 | return StrCmpiRetInt(s1, s2) == 0 ? true : false; 257 | } 258 | 259 | public static bool IsStrInList(string str, params string[] args) 260 | { 261 | return IsStrInList(str, true, args); 262 | } 263 | public static bool IsStrInList(string str, bool ignoreCase, params string[] args) 264 | { 265 | foreach (string s in args) 266 | { 267 | if (ignoreCase) 268 | { 269 | if (StrCmpi(str, s)) 270 | { 271 | return true; 272 | } 273 | } 274 | else 275 | { 276 | if (StrCmp(str, s)) 277 | { 278 | return true; 279 | } 280 | } 281 | } 282 | 283 | return false; 284 | } 285 | 286 | public static bool IsNumber(string str) 287 | { 288 | str = str.Trim(); 289 | 290 | foreach (char c in str) 291 | { 292 | if (c >= '0' && c <= '9') 293 | { 294 | } 295 | else 296 | { 297 | return false; 298 | } 299 | } 300 | 301 | return true; 302 | } 303 | 304 | public static string DateToString(DateTime dt) 305 | { 306 | if (dt.Ticks != 0) 307 | { 308 | return dt.ToString("yyyyMMdd HHmmss").Substring(2); 309 | } 310 | else 311 | { 312 | return "000000_000000"; 313 | } 314 | } 315 | 316 | public static DateTime StringToDate(string str) 317 | { 318 | str = str.Replace("(JST)", "").Trim(); 319 | 320 | try 321 | { 322 | return DateTime.Parse(str); 323 | } 324 | catch 325 | { 326 | return new DateTime(0); 327 | } 328 | } 329 | 330 | public static string ToSafeString(string str) 331 | { 332 | char[] chars = 333 | { 334 | ';', '?', '=', '<', '>', ':', '@', '%', '$', '\\', '/', '|', '\"', '\r', '\n', 335 | }; 336 | 337 | string ret = str; 338 | foreach (char c in chars) 339 | { 340 | ret = ret.Replace(c, '_'); 341 | } 342 | 343 | string ret2 = ""; 344 | 345 | foreach (char c in ret) 346 | { 347 | bool b = false; 348 | 349 | if (c >= 0x00 && c <= 0x1f) 350 | { 351 | b = true; 352 | } 353 | 354 | if (c >= 0x7f && c <= 0xff) 355 | { 356 | b = true; 357 | } 358 | 359 | if (b == false) 360 | { 361 | ret2 += c; 362 | } 363 | else 364 | { 365 | ret2 += "_"; 366 | } 367 | } 368 | 369 | return ret2; 370 | } 371 | 372 | public static byte[] Base64Decode(string src) 373 | { 374 | try 375 | { 376 | return System.Convert.FromBase64String(src); 377 | } 378 | catch 379 | { 380 | return null; 381 | } 382 | } 383 | 384 | public static string DecodeMime(string src) 385 | { 386 | string[] s = src.Split('?'); 387 | byte[] b; 388 | if (s[2] == "B") 389 | { 390 | b = System.Convert.FromBase64String(s[3]); 391 | } 392 | else 393 | { 394 | throw new Exception("Bad Encode."); 395 | } 396 | string ret = System.Text.Encoding.GetEncoding(s[1]).GetString(b); 397 | 398 | if (s.Length >= 4) 399 | { 400 | string tmp = s[s.Length - 1]; 401 | 402 | if (tmp.StartsWith("=")) 403 | { 404 | ret += tmp.Substring(1); 405 | } 406 | } 407 | 408 | return ret; 409 | } 410 | 411 | public static bool HasNullChar(string str) 412 | { 413 | if (str.IndexOf('\0') != -1) 414 | { 415 | return true; 416 | } 417 | 418 | return false; 419 | } 420 | 421 | public static bool IsMailHeaderStr(string str) 422 | { 423 | if (str == null) 424 | { 425 | return false; 426 | } 427 | if (HasNullChar(str)) 428 | { 429 | return false; 430 | } 431 | 432 | string[] sep = { ": " }; 433 | string[] tokens = str.Split(sep, StringSplitOptions.RemoveEmptyEntries); 434 | 435 | if (tokens.Length >= 2) 436 | { 437 | return true; 438 | } 439 | 440 | return false; 441 | } 442 | 443 | public static bool IsStrForBase64(string str) 444 | { 445 | string b64str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+="; 446 | 447 | foreach (char c in str) 448 | { 449 | bool b = false; 450 | 451 | foreach (char c2 in b64str) 452 | { 453 | if (c == c2) 454 | { 455 | b = true; 456 | break; 457 | } 458 | } 459 | 460 | if (b == false) 461 | { 462 | return false; 463 | } 464 | } 465 | 466 | return true; 467 | } 468 | 469 | } 470 | 471 | public class StrToken 472 | { 473 | string[] tokens; 474 | 475 | public string[] Tokens 476 | { 477 | get { return tokens; } 478 | } 479 | 480 | public string this[uint index] 481 | { 482 | get { return tokens[index]; } 483 | } 484 | 485 | public uint NumTokens 486 | { 487 | get 488 | { 489 | return (uint)Tokens.Length; 490 | } 491 | } 492 | 493 | const string defaultSplitStr = " ,\t\r\n"; 494 | 495 | public static string DefaultSplitStr 496 | { 497 | get { return defaultSplitStr; } 498 | } 499 | 500 | 501 | public StrToken(string str) 502 | : this(str, null) 503 | { 504 | } 505 | public StrToken(string str, string splitStr) 506 | { 507 | if (splitStr == null) 508 | { 509 | splitStr = defaultSplitStr; 510 | } 511 | int i, len; 512 | len = splitStr.Length; 513 | char[] chars = new char[len]; 514 | for (i = 0; i < len; i++) 515 | { 516 | chars[i] = splitStr[i]; 517 | } 518 | tokens = str.Split(chars, StringSplitOptions.RemoveEmptyEntries); 519 | } 520 | } 521 | 522 | public class StrData 523 | { 524 | string strValue; 525 | 526 | public string StrValue 527 | { 528 | get { return strValue; } 529 | } 530 | 531 | public uint IntValue 532 | { 533 | get 534 | { 535 | return Util.StrToUInt(strValue); 536 | } 537 | } 538 | 539 | public ulong Int64Value 540 | { 541 | get 542 | { 543 | return Util.StrToULong(strValue); 544 | } 545 | } 546 | 547 | public StrData(string str) 548 | { 549 | if (str == null) 550 | { 551 | str = ""; 552 | } 553 | strValue = str; 554 | } 555 | } 556 | -------------------------------------------------------------------------------- /Util.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections; 4 | using System.Security.Cryptography; 5 | using System.Web; 6 | using System.IO; 7 | using System.Drawing; 8 | 9 | public class Util 10 | { 11 | public static string TruncStr(string str, int len) 12 | { 13 | if (str.Length <= len) 14 | { 15 | return str; 16 | } 17 | else 18 | { 19 | return str.Substring(len); 20 | } 21 | } 22 | 23 | public static string GenRand() 24 | { 25 | return ByteToStr(Hash(Guid.NewGuid().ToByteArray())); 26 | } 27 | 28 | public static bool StrCmpi(string s1, string s2) 29 | { 30 | try 31 | { 32 | if (s1.ToUpper() == s2.ToUpper()) 33 | { 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | catch 40 | { 41 | return false; 42 | } 43 | } 44 | 45 | public static bool StrCmp(string s1, string s2) 46 | { 47 | try 48 | { 49 | if (s1 == s2) 50 | { 51 | return true; 52 | } 53 | 54 | return false; 55 | } 56 | catch 57 | { 58 | return false; 59 | } 60 | } 61 | 62 | public static Encoding UTF8() 63 | { 64 | return Encoding.UTF8; 65 | } 66 | 67 | public static Encoding EucJP() 68 | { 69 | return Encoding.GetEncoding("euc-jp"); 70 | } 71 | 72 | public static Encoding ShiftJIS() 73 | { 74 | return Encoding.GetEncoding("shift_jis"); 75 | } 76 | 77 | public static byte[] Hash(string str) 78 | { 79 | return Hash(Encoding.UTF8.GetBytes(str)); 80 | } 81 | 82 | public static byte[] Hash(byte[] data) 83 | { 84 | SHA1 sha1 = SHA1.Create(); 85 | return sha1.ComputeHash(data); 86 | } 87 | 88 | public static string ByteToStr(byte[] data) 89 | { 90 | StringBuilder sb = new StringBuilder(); 91 | foreach (byte b in data) 92 | { 93 | sb.Append(b.ToString("X2")); 94 | } 95 | 96 | return sb.ToString(); 97 | } 98 | 99 | public static string RandToStr6(string rand) 100 | { 101 | byte[] hash = Hash(rand + "packetix.net"); 102 | return ByteToStr(hash).Substring(0, 6); 103 | } 104 | 105 | public static bool CheckImageRand(string rand, string str) 106 | { 107 | string s = RandToStr6(rand); 108 | string tmp = str.ToUpper(); 109 | tmp = tmp.Replace("O", "0").Replace("I", "1"); 110 | return StrCmpi(s, tmp); 111 | } 112 | 113 | public static bool IsAscii(char c) 114 | { 115 | if (c >= '0' && c <= '9') 116 | { 117 | return true; 118 | } 119 | if (c >= 'A' && c <= 'Z') 120 | { 121 | return true; 122 | } 123 | if (c >= 'a' && c <= 'z') 124 | { 125 | return true; 126 | } 127 | if (c == '!' || c == '\"' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || 128 | c == '(' || c == ')' || c == '-' || c == ' ' || c == '=' || c == '~' || c == '^' || c == '_' || 129 | c == '\\' || c == '|' || c == '{' || c == '}' || c == '[' || c == ']' || c == '@' || 130 | c == '*' || c == '+' || c == '.' || c == '<' || c == '>' || 131 | c == ',' || c == '?' || c == '/') 132 | { 133 | return true; 134 | } 135 | return false; 136 | } 137 | public static bool IsAscii(string str) 138 | { 139 | foreach (char c in str) 140 | { 141 | if (IsAscii(c) == false) 142 | { 143 | return false; 144 | } 145 | } 146 | return true; 147 | } 148 | 149 | public static bool CheckMailAddress(string str) 150 | { 151 | str = str.Trim(); 152 | if (str.Length == 0) 153 | { 154 | return false; 155 | } 156 | 157 | string[] tokens = str.Split('@'); 158 | 159 | if (tokens.Length != 2) 160 | { 161 | return false; 162 | } 163 | 164 | string a = tokens[0]; 165 | string b = tokens[1]; 166 | 167 | if (a.Length == 0 || b.Length == 0) 168 | { 169 | return false; 170 | } 171 | 172 | if (b.IndexOf(".") == -1) 173 | { 174 | return false; 175 | } 176 | 177 | return IsAscii(str); 178 | } 179 | 180 | public static string GetFileSizeStr(int size) 181 | { 182 | if (size >= 1024 * 1024) 183 | { 184 | return ((double)(size) / 1024.0f / 1024.0f).ToString(".##") + " MB"; 185 | } 186 | if (size >= 1024) 187 | { 188 | return ((double)(size) / 1024.0f).ToString(".##") + " KB"; 189 | } 190 | return ((double)(size)).ToString() + " Bytes"; 191 | } 192 | 193 | 194 | public static string IntToStr(int i) 195 | { 196 | return i.ToString(); 197 | } 198 | public static string IntToStr(uint i) 199 | { 200 | return i.ToString(); 201 | } 202 | 203 | public static string LongToStr(long i) 204 | { 205 | return i.ToString(); 206 | } 207 | public static string LongToStr(ulong i) 208 | { 209 | return i.ToString(); 210 | } 211 | 212 | public static int StrToInt(string str) 213 | { 214 | try 215 | { 216 | return int.Parse(str); 217 | } 218 | catch 219 | { 220 | try 221 | { 222 | return (int)double.Parse(str); 223 | } 224 | catch 225 | { 226 | return 0; 227 | } 228 | } 229 | } 230 | public static uint StrToUInt(string str) 231 | { 232 | try 233 | { 234 | return uint.Parse(str); 235 | } 236 | catch 237 | { 238 | return 0; 239 | } 240 | } 241 | 242 | public static long StrToLong(string str) 243 | { 244 | try 245 | { 246 | return long.Parse(str); 247 | } 248 | catch 249 | { 250 | return 0; 251 | } 252 | } 253 | public static ulong StrToULong(string str) 254 | { 255 | try 256 | { 257 | return ulong.Parse(str); 258 | } 259 | catch 260 | { 261 | return 0; 262 | } 263 | } 264 | 265 | public static DateTime StrToDate(string str) 266 | { 267 | DateTime ret = new DateTime(0); 268 | str = str.Trim(); 269 | if (str.Length == 8) 270 | { 271 | int year = StrToInt(str.Substring(0, 4)); 272 | int month = StrToInt(str.Substring(4, 2)); 273 | int day = StrToInt(str.Substring(6, 2)); 274 | 275 | ret = new DateTime(year, month, day); 276 | } 277 | return ret; 278 | } 279 | 280 | public static string SafeSql(string str) 281 | { 282 | return str.Replace("'", ""); 283 | } 284 | 285 | public static bool IsFileExists(string name) 286 | { 287 | try 288 | { 289 | return File.Exists(name); 290 | } 291 | catch 292 | { 293 | return false; 294 | } 295 | } 296 | 297 | public static string GetDefaultDocumentIfExists(string dir) 298 | { 299 | string[] targets = 300 | { 301 | "default.aspx", 302 | "default.asp", 303 | "default.html", 304 | "default.htm", 305 | "index.html", 306 | "index.htm", 307 | }; 308 | 309 | foreach (string s in targets) 310 | { 311 | string name = dir + s; 312 | 313 | if (IsFileExists(name)) 314 | { 315 | return name; 316 | } 317 | } 318 | 319 | return null; 320 | } 321 | 322 | public static string ReadHtmlFile(string filename) 323 | { 324 | return File.ReadAllText(filename, Encoding.GetEncoding("shift_jis")); 325 | } 326 | 327 | public static string GetAlternativeTitleFromHtml(string src) 328 | { 329 | string tmp; 330 | string upper; 331 | int i; 332 | 333 | upper = src.ToLower(); 334 | i = upper.IndexOf(""); 335 | if (i == -1) 336 | { 337 | return null; 338 | } 339 | 340 | tmp = src.Substring(0, i); 341 | 342 | i = tmp.IndexOf(""); 343 | if (i == -1) 344 | { 345 | return null; 346 | } 347 | 348 | string ret = tmp.Substring(i + 4); 349 | 350 | if (ret.Length == 0) 351 | { 352 | return null; 353 | } 354 | else 355 | { 356 | return ret; 357 | } 358 | } 359 | 360 | public static string GetTitleFromHtml(string src) 361 | { 362 | string tmp; 363 | string upper; 364 | int i; 365 | 366 | upper = src.ToLower(); 367 | i = upper.IndexOf(""); 368 | if (i == -1) 369 | { 370 | return null; 371 | } 372 | 373 | tmp = src.Substring(0, i); 374 | 375 | i = tmp.IndexOf(""); 376 | if (i == -1) 377 | { 378 | return null; 379 | } 380 | 381 | return tmp.Substring(i + 7); 382 | } 383 | 384 | public static string GetTitleFromHtmlFile(string filename) 385 | { 386 | return GetTitleFromHtml(ReadHtmlFile(filename)); 387 | } 388 | public static string GetAlternativeTitleFromHtmlFile(string filename) 389 | { 390 | return GetAlternativeTitleFromHtml(ReadHtmlFile(filename)); 391 | } 392 | 393 | public static string GetUrlFileNameFromPath(string url) 394 | { 395 | string folder = GetUrlDirNameFromPath(url); 396 | 397 | return url.Substring(folder.Length); 398 | } 399 | 400 | public static string GetUrlDirNameFromPath(string url) 401 | { 402 | string ret = ""; 403 | string[] strs = url.Split('/'); 404 | int i; 405 | if (strs.Length >= 1) 406 | { 407 | for (i = 0; i < strs.Length - 1; i++) 408 | { 409 | ret += strs[i] + "/"; 410 | } 411 | } 412 | return ret; 413 | } 414 | 415 | public static string Encode64(string str) 416 | { 417 | return Convert.ToBase64String(Encoding.UTF8.GetBytes(str)).Replace("/", "(").Replace("+", ")"); 418 | } 419 | 420 | public static string Decode64(string str) 421 | { 422 | return Encoding.UTF8.GetString(Convert.FromBase64String(str.Replace(")", "+").Replace("(", "/"))); 423 | } 424 | 425 | public static string RemoveDefaultHtml(string url) 426 | { 427 | string tmp = url.ToLower(); 428 | if (tmp.EndsWith("/default.asp") || tmp.EndsWith("/default.aspx") || tmp.EndsWith("/default.htm") || tmp.EndsWith("/default.html")) 429 | { 430 | return GetUrlDirNameFromPath(url); 431 | } 432 | else 433 | { 434 | return url; 435 | } 436 | } 437 | 438 | public static string RemovePortFromHostHeader(string str) 439 | { 440 | try 441 | { 442 | string[] ret = str.Split(':'); 443 | 444 | return ret[0]; 445 | } 446 | catch 447 | { 448 | return str; 449 | } 450 | } 451 | 452 | public static string ToStr3(ulong v) 453 | { 454 | string tmp = LongToStr(v); 455 | int len, i; 456 | string tmp2 = ""; 457 | 458 | len = tmp.Length; 459 | 460 | for (i = len - 1; i >= 0; i--) 461 | { 462 | tmp2 += tmp[i]; 463 | } 464 | 465 | tmp = ""; 466 | 467 | for (i = 0; i < len; i++) 468 | { 469 | if (i != 0 && (i % 3) == 0) 470 | { 471 | tmp += ","; 472 | } 473 | tmp += tmp2[i]; 474 | } 475 | 476 | tmp2 = ""; 477 | len = tmp.Length; 478 | 479 | for (i = len - 1; i >= 0; i--) 480 | { 481 | tmp2 += tmp[i]; 482 | } 483 | 484 | return tmp2; 485 | } 486 | 487 | public static string DateTimeToStr(DateTime dt) 488 | { 489 | return DateTimeToStr(dt, false); 490 | } 491 | public static string DateTimeToStr(DateTime dt, bool toLocalTime) 492 | { 493 | if (toLocalTime) 494 | { 495 | dt = dt.ToLocalTime(); 496 | } 497 | 498 | return dt.ToString("yyyy年M月d日(ddd) H時m分s秒"); 499 | } 500 | 501 | public static byte[] IntToByte(uint value) 502 | { 503 | MemoryStream st = new MemoryStream(); 504 | BinaryWriter w = new BinaryWriter(st); 505 | w.Write(value); 506 | st.Seek(0, SeekOrigin.Begin); 507 | return st.ToArray(); 508 | } 509 | 510 | public static uint ByteToInt(byte[] b) 511 | { 512 | MemoryStream st = new MemoryStream(); 513 | st.Write(b, 0, b.Length); 514 | st.Seek(0, SeekOrigin.Begin); 515 | BinaryReader r = new BinaryReader(st); 516 | return r.ReadUInt32(); 517 | } 518 | 519 | public static byte[] ReverseByteArray(byte[] b) 520 | { 521 | int i, num, j; 522 | num = b.Length; 523 | byte[] ret = new byte[num]; 524 | j = 0; 525 | 526 | for (i = num - 1; i >= 0; i--) 527 | { 528 | ret[j++] = b[i]; 529 | } 530 | 531 | return ret; 532 | } 533 | 534 | public static uint ReverseEndian(uint value) 535 | { 536 | return ByteToInt(ReverseByteArray(IntToByte(value))); 537 | } 538 | 539 | public static string SafeDomainStr(string str) 540 | { 541 | string ret = str.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "").Replace("#", "") 542 | .Replace("%", "").Replace("%", "").Replace("&", "").Replace(".", ""); 543 | if (ret == "") 544 | { 545 | ret = "host"; 546 | } 547 | 548 | return ret; 549 | } 550 | 551 | public static bool CompareByte(byte[] b1, byte[] b2) 552 | { 553 | if (b1.Length != b2.Length) 554 | { 555 | return false; 556 | } 557 | int i, len; 558 | len = b1.Length; 559 | for (i = 0; i < len; i++) 560 | { 561 | if (b1[i] != b2[i]) 562 | { 563 | return false; 564 | } 565 | } 566 | return true; 567 | } 568 | 569 | public static int CompareByteRetInt(byte[] b1, byte[] b2) 570 | { 571 | int i; 572 | for (i = 0; ; i++) 573 | { 574 | int a1 = -1, a2 = -1; 575 | if (b1.Length < i) 576 | { 577 | a1 = (int)b1[i]; 578 | } 579 | if (b2.Length < i) 580 | { 581 | a2 = (int)b2[i]; 582 | } 583 | 584 | if (a1 > a2) 585 | { 586 | return 1; 587 | } 588 | else if (a1 < a2) 589 | { 590 | return -1; 591 | } 592 | if (a1 == -1 && a2 == -1) 593 | { 594 | return 0; 595 | } 596 | } 597 | } 598 | 599 | public static byte[] CloneByteArray(byte[] src) 600 | { 601 | return (byte[])src.Clone(); 602 | } 603 | } 604 | -------------------------------------------------------------------------------- /stbchecker.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 15 3 | VisualStudioVersion = 15.0.28010.2026 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stbchecker", "stbchecker.csproj", "{BA902FC8-E936-44AA-9C88-57D358BBB700}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Release|Any CPU = Release|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {BA902FC8-E936-44AA-9C88-57D358BBB700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 14 | {BA902FC8-E936-44AA-9C88-57D358BBB700}.Debug|Any CPU.Build.0 = Debug|Any CPU 15 | {BA902FC8-E936-44AA-9C88-57D358BBB700}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | {BA902FC8-E936-44AA-9C88-57D358BBB700}.Release|Any CPU.Build.0 = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | GlobalSection(ExtensibilityGlobals) = postSolution 22 | SolutionGuid = {AD05DECC-E457-42C1-B8AC-46F021023817} 23 | EndGlobalSection 24 | EndGlobal 25 | --------------------------------------------------------------------------------