void CopyCurrentRuleToClipboard() { if (CurrentRule != null) { MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); CurrentRule.Write(sw); sw.Flush(); ms.Position = 0; using (StreamReader reader = new StreamReader(ms, Encoding.ASCII)) { string contents = reader.ReadToEnd(); if (!String.IsNullOrEmpty(contents)) { //Need to make sure corrupt rules don't get pasted. System.Security.Cryptography.SHA256Managed c = new System.Security.Cryptography.SHA256Managed(); System.Text.UTF8Encoding e = new UTF8Encoding(); byte[] rep = e.GetBytes(contents); string hashstr = Convert.ToBase64String(c.ComputeHash(rep)); Clipboard.SetText(hashstr + "#" + contents); } } } }
void DoSave() { FileChanged = false; CountedStreamWriter pf = new CountedStreamWriter(FileName); LootRules.Write(pf); pf.Close(); }
public override void LoadProfile(string filename, bool newprofile) { try { #if DEBUGMSG neededid = 0; noid = 0; #endif if (newprofile) { LootRules = new cLootRules(); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)) { using (CountedStreamWriter sr = new CountedStreamWriter(fs)) { LootRules.Write(sr); } } WriteToChat("Created blank profile " + filename + "."); } else { if (!System.IO.File.Exists(filename)) { return; } LootRules = new cLootRules(); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(fs)) { if (LootRules.Read(sr, -1)) { WriteToChat("Load profile " + filename + " successful (file version " + LootRules.UTLFileVersion.ToString() + ")."); } else { WriteToChat("Load profile " + filename + " returned an error. Your entire profile may not have loaded properly."); } } } } } catch (Exception ex) { ExceptionHandler(ex); } }
private void exportRangesToolStripMenuItem_Click(object sender, EventArgs e) { System.Windows.Forms.SaveFileDialog od = new System.Windows.Forms.SaveFileDialog(); od.DefaultExt = ".ucr"; od.Filter = "VTClassic Combine Ranges|*.ucr"; od.InitialDirectory = GetVTankProfileDirectory(); od.ShowDialog(); if (od.FileName != "") { using (CountedStreamWriter pf = new CountedStreamWriter(od.FileName)) { SalvageBlock.Write(pf); } } }
public void Write(CountedStreamWriter inf) { foreach (IUTLFileBlockHandler h in FileBlocks) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); h.Write(sw); sw.Flush(); inf.WriteLine(h.BlockTypeID); inf.WriteLine(((int)sw.Count).ToString(System.Globalization.CultureInfo.InvariantCulture)); ms.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(ms); inf.Write(sr.ReadToEnd()); } }
private void toolStripButton1_Click(object sender, EventArgs e) { if (CurrentRule != null) { MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); CurrentRule.Write(sw); sw.Flush(); ms.Position = 0; using (StreamReader reader = new StreamReader(ms, Encoding.ASCII)) { string contents = reader.ReadToEnd(); if (!String.IsNullOrEmpty(contents)) { Clipboard.SetText(contents); } } } }
public override void LoadProfile(string filename, bool newprofile) { try { #if DEBUGMSG neededid = 0; noid = 0; #endif if (newprofile) { LootRules = new cLootRules(); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)) { using (CountedStreamWriter sr = new CountedStreamWriter(fs)) { LootRules.Write(sr); } } WriteToChat("Created blank profile " + filename + "."); } else { if (!System.IO.File.Exists(filename)) return; LootRules = new cLootRules(); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(fs)) { if (LootRules.Read(sr, -1)) WriteToChat("Load profile " + filename + " successful (file version " + LootRules.UTLFileVersion.ToString() + ")."); else WriteToChat("Load profile " + filename + " returned an error. Your entire profile may not have loaded properly."); } } } } catch (Exception ex) { ExceptionHandler(ex); } }