public static void Save(Stream outs, ArrayList files, ArrayList fileAssoc) { Crc crc = new Crc(true); using (StreamWriter sw = new StreamWriter(outs)) { if (files != null) { foreach (RemoteFile rm in files) { if (rm.Valid && !rm.IsStarterReplacer) { string s = rm.ToString(); crc.Update(s); sw.WriteLine(s); } } } if (fileAssoc != null) { foreach (FileAssoc fa in fileAssoc) { if ((fa != null) && fa.Valid) { string s = fa.ToString(); crc.Update(s); sw.WriteLine(s); } } } sw.WriteLine(Crc.Prefix + crc.GetValue()); } }
public void Save() { lock (this) { using (Stream s = Utils.OpenWrite(path)) { using (StreamWriter sw = new StreamWriter(s)) { Crc crc = new Crc(true); foreach (string k in data.Keys) { string v = (string)data[k]; if (v == null) { v = string.Empty; } sw.WriteLine(k + "=" + v); crc.Update(k); crc.Update(v); } sw.WriteLine(Crc.Prefix + crc.GetValue()); } } } }
public void Load() { if (!File.Exists(path)) { return; } lock (this) { string crc = string.Empty; Crc nCrc = new Crc(true); using (Stream s = Utils.OpenRead(path)) { using (StreamReader sr = new StreamReader(s)) { for (string line = sr.ReadLine(); line != null; line = sr.ReadLine()) { line = line.Trim(' ', '\t', '\r', '\n'); if (string.IsNullOrEmpty(line)) { continue; } if (line.StartsWith(Crc.Prefix)) { crc = line.Substring(Crc.Prefix.Length); continue; } if (line.StartsWith("#")) { continue; } int idx = line.IndexOf('='); if (idx <= 0) { continue; } string key = line.Substring(0, idx).Trim(); string val = line.Substring(idx + 1).Trim(); data[key] = val; nCrc.Update(key); nCrc.Update(val); } } } //if (!string.IsNullOrEmpty(crc)) //{ string newCrc = nCrc.GetValue(); if (!crc.ToLower().Equals(newCrc)) { this.data.Clear(); RawLog.Default.Log("store " + Str.Def.Get(Str.FailedCrc), true); } //} } }
private void CheckCrc(string tempFile, Monitor m) { Crc hash = new Crc(); using (Stream outs = Utils.OpenRead(tempFile)) { hash.Update(outs, m); } if (m.ShouldStop()) { return; } string fcrc = hash.GetValue(); if (!rm.crc.ToLower().Equals(fcrc)) { Utils.DeleteFile(tempFile); throw new Exception(Str.Def.Get(Str.FailedCrc) + rm.name); } }
public static ArrayList Load(StreamReader sr, ref ArrayList fileAssoc) { if (fileAssoc == null) { fileAssoc = new ArrayList(); } fileAssoc.Clear(); ArrayList files = new ArrayList(); Hashtable variables = new Hashtable(); string crc = string.Empty; Crc hash = new Crc(true); for (string line = sr.ReadLine(); line != null; line = sr.ReadLine()) { line = line.Trim(' ', '\t', '\r', '\n'); if (string.IsNullOrEmpty(line)) { continue; } else if (line.StartsWith(Crc.Prefix)) { crc = line.Substring(Crc.Prefix.Length); continue; } else if (line.StartsWith("#") && !line.StartsWith("##")) { continue; } else if (line.StartsWith("$$")) { int idx = line.IndexOf('='); if (idx < 0) { continue; } string key = line.Substring(1, idx - 1).Trim(); string val = line.Substring(idx + 1).Trim(); variables[key] = val; continue; } foreach (string k in variables.Keys) { line = line.Replace(k, (string)variables[k]); } if (line.StartsWith(FileAssoc.Prefix)) { FileAssoc fa = new FileAssoc(); fa.FromString(line); if (fa.Valid) { hash.Update(fa.ToString()); fileAssoc.Add(fa); } continue; } RemoteFile rm = new RemoteFile(); rm.Init(line); if (rm.Valid) { // add starter only if new if (rm.IsStarterReplacer) { if (rm.version.Equals(Config.Default.StarterLastVersion)) { continue; } else { string newExePath = Config.Default.GetNewStarterPath(); if (File.Exists(newExePath)) { string newExeVersion = Config.Default.StarterNewVersion; if (newExeVersion.Equals(rm.version)) { // already downloaded this starter version continue; } } } } hash.Update(rm.ToString()); files.Add(rm); } } if (!string.IsNullOrEmpty(crc)) { string newCrc = hash.GetValue(); if (!crc.ToLower().Equals(newCrc)) { throw new Exception(Str.Def.Get(Str.FailedCrc)); } } return(files); }