protected void OnUpdatesChanged(bool found = false) { string INIPath = Program.appPath + @"\updates.ini"; FileOps.DeleteFile(INIPath); StoreUpdates(mUpdateHistory); StoreUpdates(mPendingUpdates); StoreUpdates(mInstalledUpdates); StoreUpdates(mHiddenUpdates); UpdatesChaged?.Invoke(this, new UpdatesArgs(found)); }
public void ClearSavedTimers() { ResetAllTimers(); var timerfile = FileOps.CombineTimer(mapName); if (!Directory.Exists(Settings.Default.TimerDir)) { return; } FileOps.DeleteFile(timerfile); }
// Saves timers to a file for the current map private void SaveTimers() { var timerfile = FileOps.CombineTimer(mapName); if (!Settings.Default.saveSpawnTimers || mapName.Length < 3) { return; } if (Voidmaps) { MustSave = false; FileOps.DeleteFile(timerfile); return; } try { MustSave = false; LastSaveTime = DateTime.Now; if (mobsTimer2.Count != 0) { var count = 0; foreach (Spawntimer st in mobsTimer2.Values) { if (st.SpawnTimer > 10 && (string.Compare(st.zone, mapName, true) == 0)) { count++; } } if (count > 0) { using (StreamWriter sw = new StreamWriter(File.Open(timerfile, FileMode.Create))) { foreach (Spawntimer st in mobsTimer2.Values) { if (st.SpawnTimer > 10 && (string.Compare(st.zone, mapName, true) == 0)) { sw.WriteLine(st.GetAsString()); } } } } } } catch (Exception ex) { LogLib.WriteLine("Error in SaveTimers():", ex); } }
public void Update <TEntity>(TEntity entity) where TEntity : BaseEntity, new() { string file = $"storage_{typeof(TEntity).Name}.json"; string filePath = Path.Combine(_storageDirectory, file); bool fileExist = FileOps.IsExistingFile(filePath); if (!fileExist) { throw new Exception("Update operation failed! Stroage file not found."); } string content = FileOps.ReadText(filePath); IList <TEntity> dataList = (IList <TEntity>)_serializor.Deserialize <IEnumerable <TEntity> >(content); TEntity responseItem = dataList.SingleOrDefault(x => x.Id == entity.Id); if (responseItem == null) { throw new Exception($"Update operation failed! Item not found Type: {entity.GetType().Name} Id:{entity.Id}"); } int index = dataList.IndexOf(responseItem); dataList[index] = entity; //responseItem = entity; content = _serializor.Serialize(dataList).ToString(); if (fileExist) { FileOps.DeleteFile(filePath); } FileOps.WriteFile( filePath, content, new FileWriteOptions { OverwriteFileIfExists = true, CreateDirectoryIfNotExists = true }); }
public bool RemoveDomainBlocklist(string Url) { DomainBlocklist Blocklist = null; ListLock.EnterWriteLock(); if (Blocklists.TryGetValue(Url, out Blocklist)) { Blocklists.Remove(Url); } ListLock.ExitWriteLock(); if (Blocklist == null) { return(false); } string fileName = App.dataPath + @"\DnsBlockLists\" + Blocklist.FileName; FileOps.DeleteFile(fileName); ReloadBlocklists = MiscFunc.GetUTCTimeMs() + 5 * 1000; // schedule reaload return(true); }
public TEntity Insert <TEntity>(TEntity entity) where TEntity : BaseEntity, new() { IList <TEntity> responseList; string content = default(string); string file = $"storage_{typeof(TEntity).Name}.json"; string filePath = Path.Combine(_storageDirectory, file); bool fileExist = FileOps.IsExistingFile(filePath); if (fileExist) { content = FileOps.ReadText(filePath); responseList = (IList <TEntity>)_serializor.Deserialize <IEnumerable <TEntity> >(content); } else { responseList = new List <TEntity>(); } SetId(entity); responseList.Add(entity); content = _serializor.Serialize(responseList).ToString(); if (fileExist) { FileOps.DeleteFile(filePath); } FileOps.WriteFile( filePath, content, new FileWriteOptions { OverwriteFileIfExists = true, CreateDirectoryIfNotExists = true }); return(entity); }
static bool ExecuteCommands() { if (TestArg("-help") || TestArg("/?")) { string Message = "Available command line options\r\n"; string[] Help = { "Available Console Commands:", "========================================", "", "-state\t\t\tShow instalation state", "-uninstall\t\tUninstall Private Win10", "-shutdown\t\tClose Private Win10 instances", "-restart\t\tRestart Win10 and reload settings", "", "-svc_install\t\tInstall priv10 service (invokes -log_install)", "-svc_remove\t\tRemove priv10 service", "", "-log_install\t\tInstall PrivateWin10 Custom Event Log", "-log_remove\t\tRemove PrivateWin10 Custom Event Log", "", "-restore_dns\t\tRestore original DNS Configuration", "", "-console\t\tShow console with debug output", "-help\t\t\tShow this help message" }; if (!HasConsole) { MessageBox.Show(Message + string.Join("\r\n", Help)); } else { Console.WriteLine(Message); for (int j = 0; j < Help.Length; j++) { Console.WriteLine(" " + Help[j]); } } return(true); } bool bDone = false; if (TestArg("-uninstall")) { AppLog.Debug("Uninstalling Private Win10"); bDone = true; } if (TestArg("-svc_remove") || (Priv10Service.IsInstalled() && TestArg("-uninstall"))) { AppLog.Debug("Removing Service..."); Priv10Service.Uninstall(); bDone = true; } if (TestArg("-shutdown") || TestArg("-restart") || TestArg("-restore") || TestArg("-uninstall")) { AppLog.Debug("Closing instances..."); if (Priv10Service.IsInstalled()) { Priv10Service.Terminate(); } Thread.Sleep(500); foreach (var proc in Process.GetProcessesByName(App.Key)) { if (proc.Id == ProcFunc.CurID) { continue; } proc.Kill(); } bDone = true; } if (TestArg("-restore")) { string zipPath = GetArg("-restore"); try { if (zipPath == null || !File.Exists(zipPath)) { throw new Exception("Data backup zip not specifyed or invalid path"); } Console.WriteLine("Restoring settings from {0}", zipPath); string extractPath = App.dataPath; // Normalizes the path. extractPath = Path.GetFullPath(extractPath); // Ensures that the last character on the extraction path // is the directory separator char. // Without this, a malicious zip file could try to traverse outside of the expected // extraction path. if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { extractPath += Path.DirectorySeparatorChar; } // create data directory if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } // ensure its writable by non administrators FileOps.SetAnyDirSec(dataPath); // Extract the backuped files using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { foreach (ZipArchiveEntry entry in archive.Entries) { // Gets the full path to ensure that relative segments are removed. string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName)); // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that // are case-insensitive. if (!destinationPath.StartsWith(extractPath, StringComparison.Ordinal)) { continue; } Console.WriteLine("Restored file {0}", entry.FullName); if (File.Exists(destinationPath)) { FileOps.DeleteFile(destinationPath); } else if (!Directory.Exists(Path.GetDirectoryName(destinationPath))) { Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)); } entry.ExtractToFile(destinationPath); } } } catch (Exception err) { Console.WriteLine(err.Message); MessageBox.Show(Translate.fmt("msg_restore_error", err.Message), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop); } bDone = true; } if (TestArg("-restart") || TestArg("-restore")) { Thread.Sleep(500); AppLog.Debug("Starting instances..."); if (Priv10Service.IsInstalled()) { Priv10Service.Startup(); } Thread.Sleep(500); ProcessStartInfo startInfo = new ProcessStartInfo(App.exePath); startInfo.UseShellExecute = true; startInfo.Verb = "runas"; Process.Start(startInfo); bDone = true; } if (TestArg("-log_remove") || (Log.UsingEventLog() && TestArg("-uninstall"))) { AppLog.Debug("Removing Event Log..."); Log.RemoveEventLog(Key); bDone = true; } if (TestArg("-svc_install")) { AppLog.Debug("Installing Service..."); Priv10Service.Install(TestArg("-svc_start")); bDone = true; } if (TestArg("-log_install") || TestArg("-svc_install")) // service needs the event log { AppLog.Debug("Setting up Event Log..."); Log.SetupEventLog(Key); bDone = true; } if (TestArg("-restore_dns") || (DnsConfigurator.IsAnyLocalDNS() && TestArg("-uninstall"))) { AppLog.Debug("Restoring DNS Config..."); DnsConfigurator.RestoreDNS(); bDone = true; } if (TestArg("-uninstall") && AdminFunc.IsSkipUac(App.Key)) { AppLog.Debug("Removing UAC Bypass..."); AdminFunc.SkipUacEnable(App.Key, false); bDone = true; } if (TestArg("-uninstall") && App.IsAutoStart()) { AppLog.Debug("Removing Autostart..."); App.AutoStart(false); bDone = true; } if (bDone) { AppLog.Debug("done"); } if (TestArg("-state")) { Console.WriteLine(); Console.WriteLine("Instalation State:"); Console.WriteLine("========================="); // 25 Console.Write("Auto Start:\t"); Console.WriteLine(App.IsAutoStart()); Console.Write("UAC Bypass:\t"); Console.WriteLine(AdminFunc.IsSkipUac(App.Key)); Console.Write("Service:\t"); Console.WriteLine(Priv10Service.IsInstalled()); Console.Write("Event Log:\t"); Console.WriteLine(Log.UsingEventLog()); Console.Write("Local DNS:\t"); Console.WriteLine(DnsConfigurator.IsAnyLocalDNS()); Console.WriteLine(); bDone = true; } if (TestArg("-wait")) { Console.WriteLine(); for (int i = 10; i >= 0; i--) { Console.Write("\r{0}% ", i); Thread.Sleep(1000); } } return(bDone); }