private void FixPlayerSackData(string nbtFile, string nbtOutputFile, string nbtPath) { fNbt.NbtFile nbt = new fNbt.NbtFile(nbtFile); fNbt.NbtList playerInv = fNbt.NbtQuery.Get <fNbt.NbtList>(nbt.RootTag, nbtPath); foreach (fNbt.NbtCompound item in playerInv) { FixItemSackData(item, int.Parse(itemSackID.Text)); } nbt.SaveToFile(nbtOutputFile, fNbt.NbtCompression.GZip); }
public static void CreateReportFIle() { fNbt.NbtFile reportFile = new fNbt.NbtFile(new fNbt.NbtCompound("report")); string ticketniLog = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\Logs\\Ticketnik.log"; string errorLog = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\Logs\\Error.log"; string userConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; reportFile.RootTag.Add(new fNbt.NbtByteArray("Ticketnik.log", File.ReadAllBytes(ticketniLog))); //MessageBox.Show(reportFile.RootTag.Count.ToString()); reportFile.RootTag.Add(new fNbt.NbtByteArray("Error.log", File.ReadAllBytes(errorLog))); reportFile.RootTag.Add(new fNbt.NbtString("user.config cesta", userConfig)); reportFile.RootTag.Add(new fNbt.NbtString("Cesta k tic", Properties.Settings.Default.filePath)); reportFile.RootTag.Add(new fNbt.NbtByteArray("Soubor", File.ReadAllBytes(Properties.Settings.Default.filePath))); reportFile.RootTag.Add(new fNbt.NbtByteArray("user.config", File.ReadAllBytes(userConfig))); reportFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Ticketnik_crash.report", fNbt.NbtCompression.GZip); }
private void NbtSave() { if (null == levelNbt) { return; } int backupNum = 0; while (true) { try { File.Copy(loadingNbtFilePath, Path.GetDirectoryName(loadingNbtFilePath) + "\\" + Path.GetFileName(loadingNbtFilePath) + ((backupNum > 0)? "_" + (backupNum - 1): "") + ".bak"); break; } catch (IOException) { backupNum++; } } levelNbt.SaveToFile(loadingNbtFilePath, fNbt.NbtCompression.GZip); }
static void Main(string[] args) { Log.Reset(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); if (File.Exists("DllUpdater.exe")) { File.Delete("DllUpdater.exe"); } FileVersionInfo fi = FileVersionInfo.GetVersionInfo("fNbt.dll"); if (Properties.Settings.Default.Lang == "" && fi.ProductVersion != Properties.Settings.Default.fNbtString) { //kvůli updatu z předchozích verzí File.WriteAllBytes("DllUpdater.exe", Properties.Resources.DllUpdater); Log.Write("Removing old fNbt.dll", Log.Verbosity.Info); Process.Start("DllUpdater.exe", "firstRun"); Application.Exit(); } if (Application.ProductVersion.Contains("dev")) { try { Log.Write("Copying CZ.xml", Log.Verbosity.Info); File.Copy("..\\..\\CZ.xml", "CZ.xml", true); } catch (Exception e) { Log.Write("CZ.xml copy failed\r\n" + e.Message, Log.Verbosity.Error); }; } if (!File.Exists("CZ.xml")) { try { Log.Write("Downloading CZ.xml", Log.Verbosity.Info); WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/CZ.xml", "CZ.xml"); wc.Dispose(); } catch { } } if (!File.Exists("itemy.xml")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/itemy.xml", "itemy.xml"); wc.Dispose(); } catch { } } if (!File.Exists("items.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/items.png", "items.png"); wc.Dispose(); } catch { } } if (!File.Exists("terrain.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/terrain.png", "terrain.png"); wc.Dispose(); } catch { } } if (!File.Exists("ArmorSlotPics.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/ArmorSlotPics.png", "ArmorSlotPics.png"); wc.Dispose(); } catch { } } if (!Rozsirujici.Program.JednaInstance.BeziGlobalne(TimeSpan.FromSeconds(5), "Caesaruv SaveEdit")) { try { Log.Write("Starting Application Window", Log.Verbosity.Info); Application.Run(new Form1()); } catch (Exception e) { if (Application.ProductVersion.EndsWith("dev")) { Log.Write("Developer version crashed.", Log.Verbosity.Critical); MessageBox.Show(e.Message + "\r\n\r\n" + e.StackTrace); } else { Log.Write("SaveEdit crashed. Creating report file on Desktop", Log.Verbosity.Critical); fNbt.NbtFile reportFile = new fNbt.NbtFile(new fNbt.NbtCompound("report")); reportFile.RootTag.Add(new fNbt.NbtString("StackTrace", e.Message + "\r\n\r\n" + e.StackTrace)); string logFile = ""; if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\SaveEditLog.log")) { logFile = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\SaveEditLog.log"); } reportFile.RootTag.Add(new fNbt.NbtString("LogFile", logFile)); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\LastFile")) { reportFile.RootTag.Add(new fNbt.NbtByteArray("SaveFile", File.ReadAllBytes(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\LastFile")))); } reportFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SaveEdit_crash.report", fNbt.NbtCompression.GZip); MessageBox.Show(new Rozsirujici.Jazyk.Jazyk("CZ.xml").ReturnPreklad("Messages/ErrorCrash"), "SaveEdit", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { Log.Write("SaveEdit is already running", Log.Verbosity.Warning); MessageBox.Show(new Rozsirujici.Jazyk.Jazyk("CZ.xml").ReturnPreklad("Messages/AlreadyRunning")); } }