public virtual void CheckVersion(string customAbsPath = "", string customRelPath = "") { if (!Exists) { Log.F($"{(string.IsNullOrEmpty(customAbsPath) ? FullPath : customAbsPath)} not found. Skipping hash check."); return; } var localHash = HashUtils.GenerateFileHash((string.IsNullOrEmpty(customAbsPath) ? FullPath : customAbsPath)); if (UpdateManager.DatabaseHashes.Count == 0) { Log.F($"No database hashes in update manager. Skipping hash check."); return; } if (!UpdateManager.DatabaseHashes.TryGetValue(string.IsNullOrEmpty(customRelPath) ? RelativePath : customRelPath, out var remoteHash)) { Log.F($"No entry found in update manager for {(string.IsNullOrEmpty(customAbsPath) ? FullPath : customAbsPath)}. Skipping hash check."); return; } if (remoteHash == localHash) { return; } //Log.F($"Hash mismatch for {customRelPath ?? RelativePath} (local:{localHash} remote:{remoteHash})"); outdatedCount++; }
public static void CheckServersFile() { var path = Path.Combine(App.DataPath, "servers.txt"); if (!File.Exists(path) || HashUtils.GenerateFileHash(path) != DatabaseHashes["servers.txt"]) { DownloadServersFile(); } }
private async Task CheckHashes() { string hashFile; try { using var c = MiscUtils.GetDefaultWebClient(); hashFile = c.DownloadData(new Uri("https://github.com/Foglio1024/tera-used-icons/raw/master/hashes.json")).ToUTF8String(); } catch (Exception e) { Log.N("TCC icon updater", "Failed to retrieve icons hash file.\nIcons won't be updated.'", NotificationType.Error); Log.F($"Failed to retrieve hashes.json: {e}"); return; } var jHash = JObject.Parse(hashFile); var mismatched = new List <string>(); var dirs = jHash.Children().Select(j => (JProperty)j).ToList(); dirs.ForEach(jDir => { var dirPath = Path.Combine(App.ResourcesPath, "images", jDir.Name); ((JObject)jDir.Value).Children().Select(j => (JProperty)j).ToList().ForEach(jFile => { var filePath = Path.Combine(dirPath, jFile.Name); var remoteHash = jFile.Value.ToString(); var localHash = HashUtils.GenerateFileHash(filePath); if (File.Exists(filePath) && localHash == remoteHash) { return; } mismatched.Add($"{dirPath}/{jFile.Name}"); }); }); if (mismatched.Count > 100) { var ni = Log.N("TCC icon updater", "Many icons are missing, downloading the whole archive...", NotificationType.Warning, template: NotificationTemplate.Progress); _n = WindowManager.ViewModels.NotificationAreaVM.GetNotification <ProgressNotificationInfo>(ni); await DownloadArchive(); } else if (mismatched.Count > 0) { var ni = Log.N("TCC icon updater", $"Updating {mismatched.Count} icons...", NotificationType.Warning, template: NotificationTemplate.Progress); _n = WindowManager.ViewModels.NotificationAreaVM.GetNotification <ProgressNotificationInfo>(ni); await Task.Run(() => DownloadMissingIcons(mismatched)); } else { Log.N("TCC icon updater", "All icons are up to date.", NotificationType.Success); } }
private void UpdateFirestoreVersion() { var msg = new JObject { { "version", $"{_stringVersion}{_beta}" }, { "hash", HashUtils.GenerateFileHash(_exePath) } }; using var c = MiscUtils.GetDefaultWebClient(); c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; c.UploadString(_settings.FirestoreUrl, msg.ToString()); }
public static void CheckServersFile() { var path = Path.Combine(App.DataPath, "servers.txt"); if (!DatabaseHashes.TryGetValue("servers.txt", out var serversHash)) { return; } if (File.Exists(path) && HashUtils.GenerateFileHash(path) == serversHash) { return; } DownloadServersFile(); }
private static void UpdateFirestoreVersion() { var msg = new JObject { { "version", $"{_stringVersion}{_experimental}" }, { "hash", HashUtils.GenerateFileHash("D:/Repos/TCC/release/TCC.exe") } }; using (var c = MiscUtils.GetDefaultWebClient()) { c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; c.UploadString(File.ReadAllText("D:/Repos/TCC/TCC.Publisher/firestore_version_update.txt"), msg.ToString()); } }
private static async Task <JObject> BuildJsonDump(Exception ex) { return(new JObject { { "tcc_version", new JValue(App.AppVersion) }, { "id", new JValue(SessionManager.CurrentAccountName != null ? HashUtils.GenerateHash(SessionManager.CurrentAccountName) : "") }, { "tcc_hash", HashUtils.GenerateFileHash(typeof(App).Assembly.Location) }, { "exception", new JValue(ex.Message) }, { "exception_type", new JValue(ex.GetType().FullName) }, { "exception_source", new JValue(ex.Source) }, { "stack_trace", new JValue(ex.StackTrace) }, { "full_exception", new JValue(FormatFullException(ex)) }, { "thread_traces", await GetThreadTraces() }, { "inner_exception", ex.InnerException != null?BuildInnerExceptionJObject(ex.InnerException) : null }, { "game_version", new JValue(PacketAnalyzer.Factory == null ? 0 : PacketAnalyzer.Factory.ReleaseVersion) }, { "region", new JValue(SessionManager.Server != null ? SessionManager.Server.Region : "") }, { "server_id", new JValue(SessionManager.Server != null ? SessionManager.Server.ServerId.ToString() : "") }, { "settings_summary", new JObject { { "windows", new JObject { { "cooldown", SettingsHolder.CooldownWindowSettings.Enabled }, { "buffs", SettingsHolder.BuffWindowSettings.Enabled }, { "character", SettingsHolder.CharacterWindowSettings.Enabled }, { "class", SettingsHolder.ClassWindowSettings.Enabled }, { "chat", SettingsHolder.ChatEnabled }, { "group", SettingsHolder.GroupWindowSettings.Enabled } } }, { "generic", new JObject { { "proxy_enabled", SettingsHolder.EnableProxy }, } } } }, { "stats", new JObject { { "os", $"{Environment.OSVersion} {Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName")}" }, { "current_USER_objects", GetUSERObjectsCount() }, { "used_memory", Process.GetCurrentProcess().PrivateMemorySize64 }, { "uptime", DateTime.Now - Process.GetCurrentProcess().StartTime }, } } }); }
private static bool IsFileValid(string filename) { if (!File.Exists(filename)) { return(false); } if (!Settings.SettingsHolder.CheckOpcodesHash) { return(true); } var localHash = HashUtils.GenerateFileHash(filename); if (localHash == "") { WindowManager.FloatingButton.NotifyExtended("TCC", "Failed to check opcode file hash.\n Skipping download...", Data.NotificationType.Warning); return(true); } using (var c = FoglioUtils.MiscUtils.GetDefaultWebClient()) { try { var st = c.OpenRead("https://raw.githubusercontent.com/caali-hackerman/tera-data/master/mappings.json"); if (st != null) { var sr = new StreamReader(st); var sMappings = sr.ReadToEnd(); var jMappings = JObject.Parse(sMappings); var reg = SessionManager.Server.Region; var jReg = jMappings[reg]; var remoteHash = jReg["protocol_hash"].Value <string>(); if (localHash == remoteHash) { return(true); } } } catch { return(false); } } return(false); }
public virtual void CheckVersion(string customAbsPath = null, string customRelPath = null) { if (!Exists) { return; } var localHash = HashUtils.GenerateFileHash(customAbsPath ?? FullPath); if (UpdateManager.DatabaseHashes.Count == 0) { return; } if (!UpdateManager.DatabaseHashes.ContainsKey(customRelPath ?? RelativePath)) { return; } if (UpdateManager.DatabaseHashes[customRelPath ?? RelativePath] == localHash) { return; } Log.CW($"Hash mismatch for {customRelPath ?? RelativePath}"); outdatedCount++; }
public static JObject BuildJsonCrashReport(Exception ex) { var ret = new JObject { { "timestamp", new JValue(DateTime.UtcNow.ToEpoch()) }, { "tcc_version", new JValue(App.AppVersion) }, { "user_id", new JValue(App.Settings.LastAccountNameHash) }, { "tcc_hash", HashUtils.GenerateFileHash(typeof(App).Assembly.Location) }, { "exception", BuildExceptionMessage(ex) }, { "exception_type", new JValue(ex.GetType().FullName) }, { "exception_source", new JValue(ex.Source) }, { "stack_trace", new JValue(ex.StackTrace) }, { "game_version", new JValue(PacketAnalyzer.Factory == null ? 0 : PacketAnalyzer.Factory.ReleaseVersion) }, { "region", new JValue(Game.Server.Region) }, { "server_id", new JValue(Game.Server.ServerId.ToString()) }, { "settings_summary", new JObject { { "windows", new JObject { { "cooldown", App.Settings.CooldownWindowSettings.Enabled }, { "buffs", App.Settings.BuffWindowSettings.Enabled }, { "character", App.Settings.CharacterWindowSettings.Enabled }, { "class", App.Settings.ClassWindowSettings.Enabled }, { "chat", App.Settings.ChatEnabled }, { "npc", App.Settings.NpcWindowSettings.Enabled }, { "group", App.Settings.GroupWindowSettings.Enabled } } }, { "generic", new JObject { { "proxy_enabled", App.Settings.EnableProxy }, { "mode", App.ToolboxMode ? "toolbox" : "standalone" } } } } }, { "stats", new JObject { { "os", $"{Environment.OSVersion} {Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName")}" }, { "current_USER_objects", User32.GetGuiResources(Process.GetCurrentProcess().Handle, 1) }, { "used_memory", Process.GetCurrentProcess().PrivateMemorySize64 }, { "uptime", (DateTime.Now - Process.GetCurrentProcess().StartTime).TotalSeconds }, } } }; if (ex.InnerException != null) { var innEx = BuildInnerExceptionJObject(ex.InnerException); ret["inner_exception"] = innEx; } switch (ex) { case PacketParseException ppe: ret.Add("packet_opcode_name", new JValue(ppe.OpcodeName)); ret.Add("packet_data", new JValue(ppe.RawData.ToHexString())); break; case DeadlockException de: ret.Add("thread_traces", GetThreadTraces(de)); break; } return(ret); }
private static /*async*/ /*Task<JObject>*/ JObject BuildJsonDump(Exception ex) { var ret = new JObject { { "tcc_version", new JValue(App.AppVersion) }, { "id", new JValue(App.Settings.LastAccountNameHash != null ? App.Settings.LastAccountNameHash: "") }, { "tcc_hash", HashUtils.GenerateFileHash(typeof(App).Assembly.Location) }, { "exception", BuildExceptionMessage(ex) }, { "exception_type", new JValue(ex.GetType().FullName) }, { "exception_source", new JValue(ex.Source) }, { "stack_trace", new JValue(ex.StackTrace) }, { "full_exception", new JValue(FormatFullException(ex)) }, { "game_version", new JValue(PacketAnalyzer.Factory == null ? 0 : PacketAnalyzer.Factory.ReleaseVersion) }, { "region", new JValue(Game.Server != null ? Game.Server.Region : "") }, { "server_id", new JValue(Game.Server != null ? Game.Server.ServerId.ToString() : "") }, { "settings_summary", new JObject { { "windows", new JObject { { "cooldown", App.Settings.CooldownWindowSettings.Enabled }, { "buffs", App.Settings.BuffWindowSettings.Enabled }, { "character", App.Settings.CharacterWindowSettings.Enabled }, { "class", App.Settings.ClassWindowSettings.Enabled }, { "chat", App.Settings.ChatEnabled }, { "npc", App.Settings.NpcWindowSettings.Enabled }, { "group", App.Settings.GroupWindowSettings.Enabled } } }, { "generic", new JObject { { "proxy_enabled", App.Settings.EnableProxy }, { "mode", App.ToolboxMode ? "toolbox" : "standalone" } } } } }, { "stats", new JObject { { "os", $"{Environment.OSVersion} {Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName")}" }, { "current_USER_objects", GetUSERObjectsCount() }, { "used_memory", Process.GetCurrentProcess().PrivateMemorySize64 }, { "uptime", DateTime.Now - Process.GetCurrentProcess().StartTime }, } } }; if (ex.InnerException != null) { var innEx = BuildInnerExceptionJObject(ex.InnerException); ret["inner_exception"] = innEx; } if (ex is PacketParseException ppe) { ret.Add("packet_opcode_name", new JValue(ppe.OpcodeName)); ret.Add("packet_data", new JValue(ppe.RawData.ToHexString())); } if (ex is DeadlockException de) { ret.Add("thread_traces", GetThreadTraces(de)); } return(ret); }