public static Task <ServerInformationExtra> GetOnlineDataAsync(string id, CancellationToken cancellation = default(CancellationToken)) { return(LazierCached.CreateAsync(@".OnlineData:" + id, () => InternalUtils.GetOnlineDataAsync(id, UserAgent, cancellation).ContinueWith( r => { Logging.Debug(JsonConvert.SerializeObject(r.Result)); return JsonConvert.DeserializeObject <ServerInformationExtra>(r.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) ).GetValueAsync()); }
public static async Task <string> PostOnlineDataAsync(ServerInformationExtra data, CancellationToken cancellation = default(CancellationToken)) { try { var json = JsonConvert.SerializeObject(data); var key = ".PostedOnlineData:" + json.GetChecksum(); var uploaded = CacheStorage.Get <string>(key); if (uploaded != null) { return(uploaded); } var id = await InternalUtils.PostOnlineDataAsync(json, UserAgent, cancellation); if (id != null) { CacheStorage.Set(key, id); LazierCached.Set(@".OnlineData:" + id, data); } return(id); } catch (Exception e) when(e.IsCancelled()) { } catch (WebException e) when(e.Response is HttpWebResponse h) { try { var s = h.GetResponseStream()?.ReadAsStringAndDispose(); if (s != null) { var o = JObject.Parse(s); if (o["error"] != null) { NonfatalError.NotifyBackground($"Can’t share online data: {o["error"].ToString().ToSentenceMember()}", o["details"]?.ToString().ToSentence()); return(null); } } NonfatalError.NotifyBackground($"Can’t share online data: {h.StatusDescription.ToLower()}", e); } catch (Exception ex) { Logging.Warning(ex); NonfatalError.NotifyBackground("Can’t share online data", e); } } catch (Exception e) { NonfatalError.NotifyBackground("Can’t share online data", e); } return(null); }
public static void CreateAndRun(bool forceSoftwareRenderingMode) { FilesStorage.Initialize(EntryPoint.ApplicationDataDirectory); if (!AppArguments.GetBool(AppFlag.DisableLogging)) { var logFilename = EntryPoint.GetLogName("Main Log"); Logging.Initialize(FilesStorage.Instance.GetFilename("Logs", logFilename), AppArguments.GetBool(AppFlag.OptimizeLogging)); Logging.Write($"App version: {BuildInformation.AppVersion} ({BuildInformation.Platform}, {WindowsVersionHelper.GetVersion()})"); } if (AppArguments.GetBool(AppFlag.DisableSaving)) { ValuesStorage.Initialize(); CacheStorage.Initialize(); AuthenticationStorage.Initialize(); } else { ValuesStorage.Initialize(FilesStorage.Instance.GetFilename("Values.data"), InternalUtils.GetValuesStorageEncryptionKey(), AppArguments.GetBool(AppFlag.DisableValuesCompression)); CacheStorage.Initialize(FilesStorage.Instance.GetFilename("Cache.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression)); AuthenticationStorage.Initialize(FilesStorage.Instance.GetFilename("Authentication.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression)); if (MathUtils.Random(0, 10) == 0) { LazierCached.Purge(); } FatalErrorHandler.FatalError += OnFatalError; } if (AppArguments.GetBool(AppFlag.NoProxy, true)) { WebRequest.DefaultWebProxy = null; } NonfatalError.Initialize(); LocaleHelper.InitializeAsync().Wait(); var softwareRenderingModeWasEnabled = IsSoftwareRenderingModeEnabled(); if (forceSoftwareRenderingMode) { ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, true); } if (IsSoftwareRenderingModeEnabled()) { SwitchToSoftwareRendering(); } var app = new App(); // Some sort of safe mode if (forceSoftwareRenderingMode && !softwareRenderingModeWasEnabled) { Toast.Show("Safe mode", "Failed to start the last time, now CM uses software rendering", () => { if (ModernDialog.ShowMessage( "Would you like to switch back to hardware rendering? You can always do that in Settings/Appearance. App will be restarted.", "Switch back", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, false); Storage.SaveBeforeExit(); // Just in case WindowsHelper.RestartCurrentApplication(); } }); } app.Run(); }
public static void CreateAndRun(bool forceSoftwareRenderingMode) { FilesStorage.Initialize(EntryPoint.ApplicationDataDirectory); if (!AppArguments.GetBool(AppFlag.DisableLogging)) { var logFilename = EntryPoint.GetLogName("Main Log"); Logging.Initialize(FilesStorage.Instance.GetFilename("Logs", logFilename), AppArguments.GetBool(AppFlag.OptimizeLogging)); Logging.Write($"App version: {BuildInformation.AppVersion} ({BuildInformation.Platform}, {WindowsVersionHelper.GetVersion()})"); } Storage.TemporaryBackupsDirectory = FilesStorage.Instance.GetTemporaryDirectory("Storages Backups"); if (AppArguments.GetBool(AppFlag.DisableSaving)) { ValuesStorage.Initialize(); CacheStorage.Initialize(); AuthenticationStorage.Initialize(); } else { ValuesStorage.Initialize(FilesStorage.Instance.GetFilename("Values.data"), InternalUtils.GetValuesStorageEncryptionKey(), AppArguments.GetBool(AppFlag.DisableValuesCompression)); CacheStorage.Initialize(FilesStorage.Instance.GetFilename("Cache.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression)); AuthenticationStorage.Initialize(FilesStorage.Instance.GetFilename("Authentication.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression)); if (MathUtils.Random(0, 10) == 0) { LazierCached.Purge(); } FatalErrorHandler.FatalError += OnFatalError; } if (AppArguments.GetBool(AppFlag.NoProxy, true)) { WebRequest.DefaultWebProxy = null; } NonfatalError.Initialize(); LocaleHelper.InitializeAsync().Wait(); var softwareRenderingModeWasEnabled = IsSoftwareRenderingModeEnabled(); if (forceSoftwareRenderingMode) { ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, true); } if (IsSoftwareRenderingModeEnabled()) { SwitchToSoftwareRendering(); } var app = new App(); // Some sort of safe mode if (forceSoftwareRenderingMode && !softwareRenderingModeWasEnabled) { Toast.Show("Safe mode", "Failed to start the last time, now CM uses software rendering", () => { if (MessageDialog.Show( "Would you like to switch back to hardware rendering? You can always do that in Settings/Appearance. App will be restarted.", "Switch back", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, false); Storage.SaveBeforeExit(); // Just in case WindowsHelper.RestartCurrentApplication(); } }); } var move = AppArguments.Get(AppFlag.MoveApp); if (move != null && File.Exists(move)) { for (var i = 0; i < 10; i++) { if (FileUtils.TryToDelete(move) || !File.Exists(move)) { break; } Thread.Sleep(100); } Toast.Show("App moved", $"App moved from AC root folder, now Oculus Rift should work better", () => { var originalRemoved = File.Exists(move) ? "failed to remove original file" : "original file removed"; if (MessageDialog.Show( $"New location is “{MainExecutingFile.Location}”, {originalRemoved}. Please don’t forget to recreate any shortcuts you might have created.", "Content Manager is moved", new MessageDialogButton { [MessageBoxResult.Yes] = "View new location", [MessageBoxResult.No] = UiStrings.Ok }) == MessageBoxResult.Yes) { WindowsHelper.ViewFile(MainExecutingFile.Location); } }); } app.Run(); }