//in Terraria.WorldGen.do_playWorldCallback add this after moving .bak file internal static void LoadDedServBackup(string path, bool cloudSave) { path = Path.ChangeExtension(path, ".twld"); if (FileUtilities.Exists(path, cloudSave)) { FileUtilities.Copy(path, path + ".bad", cloudSave, true); } if (FileUtilities.Exists(path + ".bak", cloudSave)) { FileUtilities.Copy(path + ".bak", path, cloudSave, true); FileUtilities.Delete(path + ".bak", cloudSave); } }
//make Terraria.Player.ENCRYPTION_KEY internal //add to end of Terraria.Player.SavePlayer internal static void WriteModFile(Player player, string path, bool isCloudSave) { path = Path.ChangeExtension(path, ".tplr"); if (FileUtilities.Exists(path, isCloudSave)) { FileUtilities.Copy(path, path + ".bak", isCloudSave, true); } byte[] flags; byte[] data; using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { flags = WriteModPlayer(player, writer); writer.Flush(); data = stream.ToArray(); } } RijndaelManaged rijndaelManaged = new RijndaelManaged(); using (Stream stream = isCloudSave ? (Stream) new MemoryStream() : (Stream) new FileStream(path, FileMode.Create)) { using (CryptoStream cryptoStream = new CryptoStream(stream, rijndaelManaged.CreateEncryptor(Player.ENCRYPTION_KEY, Player.ENCRYPTION_KEY), CryptoStreamMode.Write)) { using (BinaryWriter writer = new BinaryWriter(cryptoStream)) { byte limit; for (limit = (byte)flags.Length; limit > 0; limit--) { if (flags[limit - 1] != 0) { break; } } writer.Write(limit); if (limit > 0) { writer.Write(flags, 0, limit); writer.Write(data); } writer.Flush(); cryptoStream.FlushFinalBlock(); stream.Flush(); if (isCloudSave && SocialAPI.Cloud != null) { SocialAPI.Cloud.Write(path, ((MemoryStream)stream).ToArray()); } } } } }
public bool HTML(InstanceReport report, string readFrom, string saveAs) { bool retval = true; try { string transformFile = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.TransformFile); if (!File.Exists(transformFile)) { Trace.TraceError("Error: Transform File '" + RulesEngineUtils.TransformFile + "' not found at:\n\t" + transformFile + "\nHtml Conversion aborted."); return(false); } XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(transformFile); XsltArgumentList argList = new XsltArgumentList(); argList.AddParam("asPage", string.Empty, "true"); using (FileStream fs = new FileStream(saveAs, FileMode.Create, FileAccess.Write)) { transform.Transform(readFrom, argList, fs); } string reportDirectory = Path.GetDirectoryName(saveAs); string styleSheetTo = Path.Combine(reportDirectory, RulesEngineUtils.StylesheetFile); string stylesheetFrom = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.StylesheetFile); FileUtilities.Copy(stylesheetFrom, styleSheetTo); string javascriptTo = Path.Combine(reportDirectory, RulesEngineUtils.JavascriptFile); string javascriptFrom = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.JavascriptFile); FileUtilities.Copy(javascriptFrom, javascriptTo); return(true); } catch (IOException ex) { RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message)); retval = false; } catch (System.Security.SecurityException ex) { RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message)); retval = false; } catch (ArgumentNullException ex) { RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message)); retval = false; } return(retval); }
//[Description( "SEC 140" )] public void Test_29039() { Test_Abstract.OutputFormat = (Test_Abstract.OutputFormat & ReportFormat.Xml) | ReportFormat.Html; Test_Abstract.HtmlFormat = HtmlReportFormat.Complete; const string accessionNumber = "29039"; string reportsFolder = PathCombine(this.baseDir, accessionNumber, "Reports"); CleanAndPrepareFolder(reportsFolder); string resultsFolder = PathCombine(this.baseDir, accessionNumber, "Results"); FilingSummary fs = new FilingSummary(); foreach (string from in Directory.GetFiles(resultsFolder, "R1_*.xml")) { string file = Path.GetFileName(from); string to = PathCombine(reportsFolder, file); FileUtilities.Copy(from, to); ReportHeader header = new ReportHeader(file, file); fs.MyReports.Add(header); } XRB.ReportBuilder rb = new XRB.ReportBuilder(); rb.ReportFormat = ReportFormat.Html; rb.HtmlReportFormat = HtmlReportFormat.Complete; rb.GetType().GetField("currentFilingSummary", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(rb, fs); rb.GetType().GetField("currentReportDirectory", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(rb, reportsFolder); rb.GetType().GetMethod("GenerateHtmlFiles", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(rb, null); foreach (string file in Directory.GetFiles(reportsFolder, "R1_*.htm")) { string html = File.ReadAllText(file); int start = html.IndexOf("<body"); int end = html.IndexOf("</body"); end = html.IndexOf('>', end) + 1; html = html.Substring(start, end - start); html = html.Replace("<br>", "<br />"); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(html); XmlNodeList headerRows = xDoc.SelectNodes("/body/table/tr[ th ]"); Assert.AreEqual(2, headerRows.Count, "The transform must generate 2 headers rows for the right display."); } }
public static void CopyResourcesToPath(string copyPath) { string[] resources = new string[] { RulesEngineUtils.TransformFile, RulesEngineUtils.StylesheetFile, RulesEngineUtils.JavascriptFile }; string xsltPath = string.Empty; foreach (string resource in resources) { string from = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, resource); string to = Path.Combine(copyPath, resource); FileUtilities.Copy(from, to); } }
//add near end of Terraria.IO.WorldFile.saveWorld before releasing locks internal static void WriteModFile(string path, bool isCloudSave) { path = Path.ChangeExtension(path, ".twld"); if (FileUtilities.Exists(path, isCloudSave)) { FileUtilities.Copy(path, path + ".bak", isCloudSave, true); } byte[] flags; byte[] data; using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { flags = WriteModWorld(writer); writer.Flush(); data = stream.ToArray(); } } using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { byte limit; for (limit = (byte)flags.Length; limit > 0; limit--) { if (flags[limit - 1] != 0) { break; } } writer.Write(limit); if (limit > 0) { writer.Write(flags, 0, limit); writer.Write(data); } writer.Flush(); data = stream.ToArray(); } } FileUtilities.Write(path, data, data.Length, isCloudSave); }
private static void OnDoPlayWorldCallBack(On.Terraria.WorldGen.orig_do_playWorldCallBack orig, object context) { if (Main.rand == null) { Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks); } for (int i = 0; i < 255; i++) { if (i != Main.myPlayer) { Main.player[i].active = false; } } WorldGen.noMapUpdate = true; WorldFile.loadWorld(Main.ActiveWorldFileData.IsCloudSave); if (WorldGen.loadFailed || !WorldGen.loadSuccess) { WorldFile.loadWorld(Main.ActiveWorldFileData.IsCloudSave); if (WorldGen.loadFailed || !WorldGen.loadSuccess) { bool isCloudSave = Main.ActiveWorldFileData.IsCloudSave; if (FileUtilities.Exists(Main.worldPathName + ".bak", isCloudSave)) { WorldGen.worldBackup = true; } else { WorldGen.worldBackup = false; } if (!Main.dedServ) { if (WorldGen.worldBackup) { Main.menuMode = 200; } else { Main.menuMode = 201; } return; } if (!WorldGen.worldBackup) { string text = Language.GetTextValue("Error.LoadFailedNoBackup"); /*if (Terraria.ModLoader.IO.WorldIO.customDataFail != null) * { * text = Terraria.ModLoader.IO.WorldIO.customDataFail.modName + " " + text; * text = text + "\n" + Terraria.ModLoader.IO.WorldIO.customDataFail.InnerException; * }*/ Console.WriteLine(text); return; } FileUtilities.Copy(Main.worldPathName, Main.worldPathName + ".bad", isCloudSave); FileUtilities.Copy(Main.worldPathName + ".bak", Main.worldPathName, isCloudSave); FileUtilities.Delete(Main.worldPathName + ".bak", isCloudSave); //Terraria.ModLoader.IO.WorldIO.LoadDedServBackup(Main.worldPathName, isCloudSave); WorldFile.loadWorld(Main.ActiveWorldFileData.IsCloudSave); if (WorldGen.loadFailed || !WorldGen.loadSuccess) { WorldFile.loadWorld(Main.ActiveWorldFileData.IsCloudSave); if (WorldGen.loadFailed || !WorldGen.loadSuccess) { FileUtilities.Copy(Main.worldPathName, Main.worldPathName + ".bak", isCloudSave); FileUtilities.Copy(Main.worldPathName + ".bad", Main.worldPathName, isCloudSave); FileUtilities.Delete(Main.worldPathName + ".bad", isCloudSave); //Terraria.ModLoader.IO.WorldIO.RevertDedServBackup(Main.worldPathName, isCloudSave); string text2 = Language.GetTextValue("Error.LoadFailed"); /*if (Terraria.ModLoader.IO.WorldIO.customDataFail != null) * { * text2 = Terraria.ModLoader.IO.WorldIO.customDataFail.modName + " " + text2; * text2 = text2 + "\n" + * Terraria.ModLoader.IO.WorldIO.customDataFail.InnerException; * }*/ Console.WriteLine(text2); return; } } } } if (Main.mapEnabled) { Main.Map.Load(); } if (Main.netMode != 2) { if (Main.sectionManager == null) { Main.sectionManager = new WorldSections(Main.maxTilesX / 200, Main.maxTilesY / 150); } Main.sectionManager.SetAllFramesLoaded(); } while (Main.loadMapLock) { float num = (float)Main.loadMapLastX / (float)Main.maxTilesX; Main.statusText = Lang.gen[68].Value + " " + (int)(num * 100f + 1f) + "%"; Thread.Sleep(0); if (!Main.mapEnabled) { break; } } if (Main.gameMenu) { Main.gameMenu = false; } if (Main.netMode == 0 && Main.anglerWhoFinishedToday.Contains(Main.player[Main.myPlayer].name)) { Main.anglerQuestFinished = true; } Main.OnTick += FinishPlayWorld; }