Ejemplo n.º 1
0
        public void UpdateToRelativePaths()
        {
            var toRemove = new List <string>();
            var toAdd    = new Dictionary <string, CacheEntry>();

            foreach (var path in CachedEntries.Keys)
            {
                if (Path.IsPathRooted(path))
                {
                    var relativePath = ModTek.GetRelativePath(path, ModTek.GameDirectory);

                    toAdd[relativePath] = CachedEntries[path];
                    toRemove.Add(path);

                    toAdd[relativePath].CachePath = ModTek.GetRelativePath(toAdd[relativePath].CachePath, ModTek.GameDirectory);
                    foreach (var merge in toAdd[relativePath].Merges)
                    {
                        merge.Path = ModTek.GetRelativePath(merge.Path, ModTek.GameDirectory);
                    }
                }
            }

            foreach (var addKVP in toAdd)
            {
                CachedEntries.Add(addKVP.Key, addKVP.Value);
            }

            foreach (var path in toRemove)
            {
                CachedEntries.Remove(path);
            }
        }
Ejemplo n.º 2
0
        public void UpdateToRelativePaths()
        {
            var toRemove = new List <string>();
            var toAdd    = new Dictionary <string, DateTime>();

            foreach (var path in Entries.Keys)
            {
                if (!Path.IsPathRooted(path))
                {
                    continue;
                }

                var relativePath = ModTek.GetRelativePath(path, ModTek.GameDirectory);
                toAdd[relativePath] = Entries[path];
                toRemove.Add(path);
            }

            foreach (var addKVP in toAdd)
            {
                Entries.Add(addKVP.Key, addKVP.Value);
            }

            foreach (var path in toRemove)
            {
                Entries.Remove(path);
            }
        }
            private IEnumerator RunWorkList()
            {
                var sw = new Stopwatch();

                sw.Start();
                foreach (var workFunc in WorkList)
                {
                    var  workEnumerator = workFunc.Invoke();
                    bool didWork;

                    do
                    {
                        try
                        {
                            didWork = workEnumerator.MoveNext();
                        }
                        catch (Exception e)
                        {
                            LogException("\nUncaught ModTek exception!", e);

                            Slider.value     = 1.0f;
                            SliderText.text  = "ModTek Died!";
                            LoadingText.text = $"See \"{ModTek.GetRelativePath(LogPath, ModTek.GameDirectory)}\"";

                            ModTek.Finish();

                            yield break;
                        }

                        var report = workEnumerator.Current;

                        if (sw.ElapsedMilliseconds <= FRAME_TIME && !report.ForceFrame)
                        {
                            continue;
                        }

                        Slider.value     = report.Progress;
                        SliderText.text  = report.SliderText;
                        LoadingText.text = report.LoadingText;

                        sw.Reset();
                        sw.Start();
                        yield return(null);
                    }while (didWork);

                    yield return(null);
                }

                Slider.value     = 1.0f;
                SliderText.text  = "Game now loading";
                LoadingText.text = "";
                yield return(null);

                FinishAction.Invoke();
            }
Ejemplo n.º 4
0
        public static void Postfix()
        {
            if (ModTek.FailedToLoadMods.Count <= 0)
            {
                return;
            }

            GenericPopupBuilder.Create("Some Mods Didn't Load",
                                       $"Check \"{ModTek.GetRelativePath(Logger.LogPath, ModTek.GameDirectory)}\" for more info\n\n"
                                       + string.Join(", ", ModTek.FailedToLoadMods.ToArray()))
            .AddButton("Continue")
            .Render();
            ModTek.FailedToLoadMods.Clear();
        }
Ejemplo n.º 5
0
        public static void Clear()
        {
            if (tmProText == null)
            {
                return;
            }

            tmProText.text = "";
            currentMessage = "[ModTek] Detected errors (might not be important!) -- For more info check ";

            var cleanLogPath = Path.Combine(ModTek.ModsDirectory, "cleaned_output_log.txt");

            if (File.Exists(cleanLogPath))
            {
                currentMessage += $"\"{ModTek.GetRelativePath(cleanLogPath, ModTek.GameDirectory)}\"\n";
            }
            else
            {
                currentMessage += $"\"output_log.txt\"\n";
            }
        }
Ejemplo n.º 6
0
        public string GetOrCreateCachedEntry(string absolutePath, List <string> mergePaths)
        {
            absolutePath = Path.GetFullPath(absolutePath);
            var relativePath = ModTek.GetRelativePath(absolutePath, ModTek.GameDirectory);

            Log("");

            if (!CachedEntries.ContainsKey(relativePath) || !CachedEntries[relativePath].MatchesPaths(absolutePath, mergePaths))
            {
                var cachedAbsolutePath = Path.GetFullPath(Path.Combine(ModTek.CacheDirectory, relativePath));
                var cachedEntry        = new CacheEntry(cachedAbsolutePath, absolutePath, mergePaths);

                if (cachedEntry.HasErrors)
                {
                    return(null);
                }

                CachedEntries[relativePath] = cachedEntry;

                Log($"Merge performed: {Path.GetFileName(absolutePath)}");
            }
            else
            {
                Log($"Cached merge: {Path.GetFileName(absolutePath)} ({File.GetLastWriteTime(CachedEntries[relativePath].CacheAbsolutePath):G})");
            }

            Log($"\t{relativePath}");

            foreach (var contributingPath in mergePaths)
            {
                Log($"\t{ModTek.GetRelativePath(contributingPath, ModTek.GameDirectory)}");
            }

            Log("");

            CachedEntries[relativePath].CacheHit = true;
            return(CachedEntries[relativePath].CacheAbsolutePath);
        }
Ejemplo n.º 7
0
        public bool HasCachedEntry(string originalPath, List <string> mergePaths)
        {
            var relativePath = ModTek.GetRelativePath(originalPath, ModTek.GameDirectory);

            return(CachedEntries.ContainsKey(relativePath) && CachedEntries[relativePath].MatchesPaths(originalPath, mergePaths));
        }
Ejemplo n.º 8
0
            public CacheEntry(string absolutePath, string originalAbsolutePath, List <string> mergePaths)
            {
                cacheAbsolutePath   = absolutePath;
                CachePath           = ModTek.GetRelativePath(absolutePath, ModTek.GameDirectory);
                ContainingDirectory = Path.GetDirectoryName(absolutePath);
                OriginalTime        = File.GetLastWriteTimeUtc(originalAbsolutePath);

                if (string.IsNullOrEmpty(ContainingDirectory))
                {
                    HasErrors = true;
                    return;
                }

                foreach (var mergePath in mergePaths)
                {
                    Merges.Add(new PathTimeTuple(ModTek.GetRelativePath(mergePath, ModTek.GameDirectory), File.GetLastWriteTimeUtc(mergePath)));
                }

                Directory.CreateDirectory(ContainingDirectory);

                // do json merge if json
                if (Path.GetExtension(absolutePath)?.ToLowerInvariant() == ".json")
                {
                    // get the parent JSON
                    JObject parentJObj;
                    try
                    {
                        parentJObj = ModTek.ParseGameJSONFile(originalAbsolutePath);
                    }
                    catch (Exception e)
                    {
                        LogException($"\tParent JSON at path {originalAbsolutePath} has errors preventing any merges!", e);
                        HasErrors = true;
                        return;
                    }

                    using (var writer = File.CreateText(absolutePath))
                    {
                        // merge all of the merges
                        foreach (var mergePath in mergePaths)
                        {
                            try
                            {
                                // since all json files are opened and parsed before this point, they won't have errors
                                JSONMerger.MergeIntoTarget(parentJObj, ModTek.ParseGameJSONFile(mergePath));
                            }
                            catch (Exception e)
                            {
                                LogException($"\tMod JSON merge at path {ModTek.GetRelativePath(mergePath, ModTek.GameDirectory)} has errors preventing merge!", e);
                            }
                        }

                        // write the merged onto file to disk
                        var jsonWriter = new JsonTextWriter(writer)
                        {
                            Formatting = Formatting.Indented
                        };
                        parentJObj.WriteTo(jsonWriter);
                        jsonWriter.Close();
                    }

                    return;
                }

                // do file append if not json
                using (var writer = File.CreateText(absolutePath))
                {
                    writer.Write(File.ReadAllText(originalAbsolutePath));

                    foreach (var mergePath in mergePaths)
                    {
                        writer.Write(File.ReadAllText(mergePath));
                    }
                }
            }