public static bool loadConfig <T>(string fileName, ref T result, CallBack_Void_S onUpdateCallback, bool isDefault = false) where T : new() { fileName = CheckReplaceFile(fileName); if (onUpdateCallback != null) { if (!updateCallbacks.ContainsKey(fileName)) { updateCallbacks.Add(fileName, null); } updateCallbacks[fileName] = onUpdateCallback; } bool flag = false; bool flag2 = false; string path = PathConfig.getFilePath(ConfigType.XML, fileName, true); if (File.Exists(path) && !isDefault) { flag = FileTool.OpenSerializedInfo <T>(path, ref result); if (!flag) { Debug.Log(fileName + " 更新配置文件损坏"); flag2 = true; File.Delete(path); } } if ((((T)result) == null) || !flag) { TextAsset asset = Resources.Load("data/" + fileName, typeof(TextAsset)) as TextAsset; if ((asset == null) || string.IsNullOrEmpty(asset.text)) { return(flag2); } string text = asset.text; MemoryStream input = new MemoryStream(); input.Write(asset.bytes, 0, asset.bytes.Length); input.Seek(0L, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(input, Encoding.UTF8); try { string str3 = ""; if (reader.ReadInt32() == 5) { int num = reader.ReadInt32(); num = reader.ReadInt32(); str3 = MD5Code.Decode(reader.ReadString()); Debug.LogWarning(fileName + " 文件启用加密"); } else { Debug.LogWarning(fileName + " 文件没有加密"); } if (!string.IsNullOrEmpty(str3)) { text = str3; } } catch (Exception exception) { Debug.LogError(fileName + " 解析出错 : " + exception.Message); } finally { if (reader != null) { reader.Close(); } } FileTool.OpenSerializedInfoByContent <T>(text, ref result); } return(flag2); }
public static string DecryptFile(string filePath) { if (File.Exists(filePath)) { FileStream input = null; StreamReader reader = null; BinaryReader reader2 = null; try { FileInfo info = new FileInfo(filePath); input = new FileStream(filePath, FileMode.Open); reader2 = new BinaryReader(input, Encoding.UTF8); bool flag = false; string source = ""; try { if (reader2.ReadInt32() == BinaryInsertNum) { flag = true; reader2.ReadInt32(); reader2.ReadInt32(); source = reader2.ReadString(); source = MD5Code.Decode(source); } } catch (Exception exception) { Debug.LogError(filePath + "_____DecryptFile Error : " + exception.Message); } finally { if (reader2 != null) { reader2.Close(); } if (input != null) { input.Close(); } } if (!flag) { input = new FileStream(filePath, FileMode.Open); reader = new StreamReader(input); source = reader.ReadToEnd(); } return(source); } catch { } finally { if (reader != null) { reader.Close(); } if (reader2 != null) { reader2.Close(); } if (input != null) { input.Close(); } } } return(""); }