Example #1
0
 private static CodeCookerCache InvalidateCache(string scenesPath)
 {
     if (Directory.Exists(scenesPath))
     {
         ScenesCodeCooker.RetryUntilSuccessDeleteDirectory(scenesPath);
     }
     return(new CodeCookerCache());
 }
Example #2
0
        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());
                }
            }
        }