コード例 #1
0
        private static Branch ApplyModChanges(Repository repo, Branch ctxBranch, string cvStr, Mod mod)
        {
            Branch branch = repo.CreateBranch(GetModBranchName(mod));

            Commands.Checkout(repo, branch);
            foreach (FileInfo file in new RecursiveFileIterator(mod.ExtractedPath))
            {
                Directory.CreateDirectory(RecursiveFileIterator.GetRelativeDirectory(file, mod.ExtractedPath));
                string relName = RecursiveFileIterator.GetRelativeName(file, mod.ExtractedPath);
                File.Copy(file.FullName, repo.Info.Path + relName, true);
                repo.Index.Add(relName);
            }
            repo.Commit("Added files for mod " + mod.Name, _sig, _sig, _cmtOpts);
            Commands.Checkout(repo, ctxBranch);
            return(branch);
        }
コード例 #2
0
        public static bool Compile(OrderedDictionary <string, Mod> mods, string targetVersion, bool clear)
        {
            bool keepOpen = true;

            if (mods.Count > 0)
            {
                bool valid = true;
                try {
                    LoadVersionInfo();
                } catch (Exception e) {
                    ConsoleUtils.ErrorLn(e.Message);
                    ConsoleUtils.WarnLn("Compilation aborted.");
                    valid = false;
                }
                if (valid)
                {
                    int i = 0;
                    List <OrderedMod> mods2 = mods.Select(x => new OrderedMod(x.Value, i++)).ToList();
                    mods2.Sort((a, b) => {
                        int res = VersionCompare(a.Mod.Version, b.Mod.Version);
                        return(res != 0 ? res : a.Position.CompareTo(b.Position));
                    });
                    int[]      vTarget        = Mod.GetConcreteVersion(targetVersion);
                    int[]      currentVersion = mods2[0].Mod.Version;
                    Repository repo           = GitSetUp(mods2[0].Mod);
                    foreach (OrderedMod mod in mods2)
                    {
                        if (VersionCompare(mod.Mod.Version, vTarget) > 0)
                        {
                            ConsoleUtils.WarnLn("Mod \"" + mod.Mod.Name + "\" is targeting a newer version of Stellaris then compilation is targeting.");
                            ConsoleUtils.WarnLn("(Mod needs " + mod.Mod.VersionString + " but compilation is targeting " + targetVersion + ").");
                            ConsoleUtils.WarnLn("Skipping mod...");
                        }
                        else
                        {
                            int cmp = VersionCompare(mod.Mod.Version, currentVersion);
                            if (cmp > 0)
                            {
                                ChangeCoreVersion(currentVersion, mod.Mod);
                                currentVersion = mod.Mod.Version;
                            }
                            ApplyMod(mod.Mod);
                        }
                    }
                    string outDir = TearDownGit(repo);



//					int[] version = GetConcreteVersion(targetVersion);
                    //string vStr = GetVersionString(version);
                    //Console.WriteLine("Compiling against Stellaris " + vStr + "...");
                    //string gameFiles = GetGameFiles(version, "$CORE " + vStr, out valid);
                    if (valid)
                    {
                        /*
                         * var usedLines = new Dictionary<string, Dictionary<int, Mod>>();
                         * foreach (KeyValuePair<string, Mod> kvp in mods) {
                         *      Mod mod = kvp.Value;
                         *      //int[] modV = GetConcreteVersion(mod.Version);
                         *      //string modVStr = GetVersionString(modV);
                         *      bool compileThis = true;
                         *      if (vStr == modVStr) {
                         *              List<string> conflicts = GetConflicts(gameFiles, mod);
                         *              ConsoleUtils.WarnLn("Compilation is targeting " + vStr + " but mod \"" + mod.Name + "\" is targeting " + modVStr + ".");
                         *              if (conflicts.Count > 0) {
                         *                      ConsoleUtils.WarnLn("Vanilla files have been overridden - compiling this mod may lead to an unstable end product.");
                         *                      ConsoleUtils.WarnLn("List of overridden files:");
                         *                      foreach (string file in conflicts) {
                         *                              ConsoleUtils.WarnLn("  " + file);
                         *                      }
                         *              } else {
                         *                      ConsoleUtils.WarnLn("No vanilla files have been overriden, but features used by the mod may have changed between versions.");
                         *              }
                         *              ConsoleUtils.Warn("Do you want to compile this mod? (y/n): ");
                         *              bool reading = true;
                         *              do {
                         *                      string line = Console.ReadLine();
                         *                      if (line != null) {
                         *                              line = line.Trim().ToLower();
                         *                              switch (line) {
                         *                                      case "y":
                         *                                      case "yes":
                         *                                              compileThis = true;
                         *                                              reading = false;
                         *                                              break;
                         *                                      case "n":
                         *                                      case "no":
                         *                                              compileThis = false;
                         *                                              reading = false;
                         *                                              break;
                         *                                      default:
                         *                                              ConsoleUtils.Warn("Invalid argument. Please specify y/n: ");
                         *                                              break;
                         *                              }
                         *                      } else {
                         *                              reading = false;
                         *                              valid = false;
                         *                              keepOpen = false;
                         *                      }
                         *              } while (reading);
                         *              Console.WriteLine();
                         *      }
                         *      if (valid) {
                         *              if (compileThis) {
                         *                      Console.WriteLine("Compiling \"" + ResolveName(mod.Name) + "\"...");
                         *                      ModDiffer.ApplyDiff(gameFiles, mod, usedLines);
                         *              } else {
                         *                      Console.WriteLine("Skipping mod...");
                         *              }
                         *      }
                         * }
                         * if (valid) {
                         *      if (clear) {
                         *              mods.Clear();
                         *      }
                         * }
                         */
                    }
                }
            }
            else
            {
                ConsoleUtils.ErrorLn("No mods have been loaded - compilation aborted.");
            }
            return(keepOpen);
        }
コード例 #3
0
 private static string GetModBranchName(Mod mod)
 {
     return("MOD_" + mod.GetHashCode());
 }