private async void ClearCache() { SettingsViewModel settingsViewModel = this; bool isNeedRestart = false; if (Cef.IsInitialized) { if (await settingsViewModel.ShowYesOrNoDialogAsync("Запрос", "Для удаления данных, нужен перезапуск приложения.") == MessageDialogResult.Negative) { return; } isNeedRestart = true; CefSharpShutdown.ShutDown(true); CefSharpShutdown.KillProcess(); } try { if (Directory.Exists(ClientConfig.AppDataPath + "\\\\BrowserData\\cache")) { Directory.Delete(ClientConfig.AppDataPath + "\\\\BrowserData\\cache", true); } await settingsViewModel.ShowSuccessDialogAsync("Все настройки браузера были удалены."); if (isNeedRestart) { settingsViewModel.Restart(); Application.Current.Shutdown(); } } catch (Exception ex) { await settingsViewModel.ShowErrorDialogAsync("Проблема с очисткой данных! " + Environment.NewLine + ex.Message); } }
public StartScreenViewModel(Action closeCallback) { this._wbClient.Encoding = Encoding.UTF8; this._wbClient.Proxy = (IWebProxy)null; this._closeCallback = closeCallback; CefSharpShutdown.KillProcess(); Task.Factory.StartNew(new Action(this.UpdateSettings)); }
private async void ResetBrowser() { SettingsViewModel settingsViewModel = this; bool isNeedRestart = false; if (Cef.IsInitialized) { if (await settingsViewModel.ShowYesOrNoDialogAsync("Запрос", "Для сброса браузера, нужен перезапуск приложения.") == MessageDialogResult.Negative) { return; } isNeedRestart = true; CefSharpShutdown.ShutDown(true); CefSharpShutdown.KillProcess(); } try { DirectoryInfo directoryInfo = new DirectoryInfo(ClientConfig.AppDataPath + "\\\\BrowserData\\cache"); if (directoryInfo.Exists) { directoryInfo.Delete(true); } int num = 0; FakeProfileFactory fakeProfileFactory = new FakeProfileFactory(); FakeProfileCompaer fakeProfileCompaer = new FakeProfileCompaer(); while (num < 100) { ++num; FakeProfile fakeProfile = fakeProfileFactory.Generate(); if (!settingsViewModel.FakeProfiles.Contains <FakeProfile>(fakeProfile, (IEqualityComparer <FakeProfile>)fakeProfileCompaer)) { settingsViewModel.FakeProfiles.Add(fakeProfile); settingsViewModel.SaveUserAgents(settingsViewModel.FakeProfiles); settingsViewModel.CurrentSettings.UserSettings.FakeProfile = fakeProfile; settingsViewModel.CurrentUserAgent = fakeProfile.UserAgent; break; } } if (num > 99) { await settingsViewModel.ShowErrorDialogAsync("Не удалось сгенерировать уникальный UserAgent(который вы еще не использовали). Попробуйте еще раз или поменяйте настройки генерации"); return; } Settings.Save(settingsViewModel.CurrentSettings); await settingsViewModel.ShowSuccessDialogAsync("Браузер сброшен."); if (isNeedRestart) { settingsViewModel.Restart(); Application.Current.Shutdown(); } } catch (Exception ex) { await settingsViewModel.ShowErrorDialogAsync("Проблема со сбросом браузера! " + Environment.NewLine + ex.Message); } }