public static CodeCookerCache LoadCodeCookerCache() { var scenesPath = $@"{The.Workspace.ProjectDirectory}/{The.Workspace.Title}.GeneratedScenes/Scenes"; var codeCachePath = GetCodeCachePath(); if (!File.Exists(codeCachePath)) { // Clean Generated Scenes folder of legacy files if there's no cache if (Directory.Exists(scenesPath)) { ScenesCodeCooker.RetryUntilSuccessDeleteDirectory(scenesPath); } return(new CodeCookerCache()); } else if (!Directory.Exists(scenesPath)) { return(new CodeCookerCache()); } else { try { CodeCookerCache cache; using (FileStream stream = new FileStream(codeCachePath, FileMode.Open, FileAccess.Read, FileShare.None)) { var jd = new Yuzu.Json.JsonDeserializer(); cache = (CodeCookerCache)jd.FromStream(new CodeCookerCache(), stream); } if (!cache.IsActual) { throw new System.Exception("Code cooker cache has deprecated version."); } using (new DirectoryChanger(The.Workspace.ProjectDirectory)) { var projectName = The.Workspace.Title; foreach (var platform in Enum.GetValues(typeof(TargetPlatform))) { var platformName = Enum.GetName(typeof(TargetPlatform), platform); var projectPath = $"{projectName}.GeneratedScenes/{projectName}.GeneratedScenes.{platformName}.csproj"; if (File.Exists(projectPath)) { var projectFilesCache = cache.GeneratedProjectFileToModificationDate; if (!projectFilesCache.ContainsKey(projectPath) || File.GetLastWriteTime(projectPath) > projectFilesCache[projectPath]) { // Consider cache inconsistent if generated project files were modified from outside return(new CodeCookerCache()); } } } } return(cache); } catch { return(new CodeCookerCache()); } } }
public static WorkspaceConfig Load() { try { using (FileStream stream = new FileStream(GetConfigPath(), FileMode.Open, FileAccess.Read, FileShare.None)) { var jd = new Yuzu.Json.JsonDeserializer(); return((WorkspaceConfig)jd.FromStream(new WorkspaceConfig(), stream)); } } catch { return(new WorkspaceConfig()); } }
public override void Execute() { var dlg = new FileDialog { AllowedFileTypes = new string[] { "layout" }, Mode = FileDialogMode.Open }; if (dlg.RunModal()) { string path = dlg.FileName; try { using (var fs = new FileStream(path, FileMode.OpenOrCreate)) { DockManager.State state = deserializer.FromStream( new DockManager.State(), fs ) as DockManager.State; DockManager.Instance.ImportState(state); } } catch (System.Exception e) { AlertDialog.Show(e.Message); } } }
private Widget CreateThemeEditor() { var pane = new Widget { Layout = new VBoxLayout { Spacing = 10 }, Padding = contentPadding }; var themeEditor = new ColorThemeEditor() { Layout = new VBoxLayout { Spacing = 10 }, Padding = contentPadding }; bool firstCall = true; pane.AddChangeWatcher(() => themeEditor.Version, _ => { if (firstCall) { firstCall = false; return; } themeChanged = true; themeEdited = true; }); var darkIcons = CreateDarkIconsSwitch(pane); var loadDarkButton = new ThemedButton("Dark preset") { Clicked = () => { AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Dark; AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateDarkTheme(); AppUserPreferences.Instance.ColorTheme = ColorTheme.CreateDarkTheme(); themeEditor.Rebuild(); themeChanged = true; } }; var loadLightButton = new ThemedButton("Light preset") { Clicked = () => { AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Light; AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateLightTheme(); AppUserPreferences.Instance.ColorTheme = ColorTheme.CreateLightTheme(); themeEditor.Rebuild(); themeChanged = true; } }; var saveButton = new ThemedButton("Save theme") { Clicked = () => { var dlg = new FileDialog { AllowedFileTypes = new string[] { "theme" }, Mode = FileDialogMode.Save }; if (dlg.RunModal()) { string path = dlg.FileName; var serializer = new Yuzu.Json.JsonSerializer(); try { var limeTheme = AppUserPreferences.Instance.LimeColorTheme; var theme = AppUserPreferences.Instance.ColorTheme; using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) { serializer.ToStream(new List <object> { limeTheme, theme }, fileStream); } } catch (System.Exception e) { AlertDialog.Show(e.Message); } } } }; var loadButton = new ThemedButton("Load theme") { Clicked = () => { var dlg = new FileDialog { AllowedFileTypes = new string[] { "theme" }, Mode = FileDialogMode.Open }; if (dlg.RunModal()) { string path = dlg.FileName; var deserializer = new Yuzu.Json.JsonDeserializer(); try { using (var fs = new FileStream(path, FileMode.OpenOrCreate)) { var read = deserializer.FromStream(new List <object>(), fs) as List <object>; AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Custom; AppUserPreferences.Instance.LimeColorTheme = (Theme.ColorTheme)read[0]; AppUserPreferences.Instance.ColorTheme = (ColorTheme)read[1]; } } catch (System.Exception e) { AlertDialog.Show(e.Message); } } themeEditor.Rebuild(); themeChanged = true; } }; var buttons = new Widget { Layout = new HBoxLayout { Spacing = 4 }, Nodes = { loadDarkButton, loadLightButton, saveButton, loadButton } }; pane.AddNode(buttons); pane.AddNode(themeEditor); return(pane); }