private static void UpdatePatches(string dcsRoot, string patchSet, string outputPath) { // determine DCS version string autoUpdatePath = Path.Combine(dcsRoot, "autoupdate.cfg"); string versionString = JsonConvert.DeserializeObject <AutoUpdateConfig>(File.ReadAllText(autoUpdatePath)) .Version; string dcsVersion = PatchVersion.SortableString(versionString); // now build patches based on files changed in repo string patchesPath = outputPath ?? FileSystem.FindNearestDirectory("Patching\\Patches"); Console.WriteLine($"writing patches for {dcsVersion} to {patchesPath}"); int nCount = 0; using (Repository repo = new Repository(dcsRoot)) { foreach (StatusEntry item in repo.RetrieveStatus(new StatusOptions())) { if (item.State == FileStatus.ModifiedInWorkdir) { string source; string target; Debug.WriteLine(item.FilePath); Blob blob = repo.Head.Tip[item.FilePath].Target as Blob; using (var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8)) { source = content.ReadToEnd(); } string workingPath = Path.Combine(repo.Info.WorkingDirectory, item.FilePath); using (var content = new StreamReader(workingPath, Encoding.UTF8)) { target = content.ReadToEnd(); } string patchPath = Path.Combine(patchesPath, "DCS", dcsVersion, patchSet, $"{item.FilePath}.gpatch"); string reversePath = Path.Combine(patchesPath, "DCS", dcsVersion, patchSet, $"{item.FilePath}.grevert"); string outputDirectoryPath = Path.GetDirectoryName(patchPath); if (outputDirectoryPath != null && !Directory.Exists(outputDirectoryPath)) { Directory.CreateDirectory(outputDirectoryPath); } Console.WriteLine($"writing patch {patchPath}"); WritePatch(source, target, patchPath); WritePatch(target, source, reversePath); nCount++; } } } if (nCount == 0) { Console.WriteLine($"no patch files written, does {dcsRoot} not have any current changes in the working directory?"); } }
private static void EditInstallation(string dcsRootPath, string jsonDirPath) { if (jsonDirPath == null) { if (!FileSystem.TryFindNearestDirectory("Tools\\ToolsCommon\\Data\\Viewports", out jsonDirPath)) { jsonDirPath = FileSystem.FindNearestDirectory("Data\\Viewports"); } } // open DCS installation location if (!InstallationLocation.TryLoadLocation(dcsRootPath, true, out InstallationLocation dcs)) { throw new Exception($"failed to open DCS installation at {dcsRootPath}"); } // pick JSON file from the given ones based on version number string exactName = $"ViewportTemplates_{PatchVersion.SortableString(dcs.Version)}.json"; string versionedJsonPath = ""; foreach (string candidate in Directory.EnumerateFiles(jsonDirPath, "ViewportTemplates_*.json", SearchOption.AllDirectories)) { string candidateName = Path.GetFileName(candidate); if (string.Compare(candidateName, exactName, StringComparison.InvariantCulture) > 0) { continue; } // applies if (string.Compare(candidateName, versionedJsonPath, StringComparison.InvariantCulture) > 0) { // new best match versionedJsonPath = candidate; } } string json = File.ReadAllText(Path.Combine(jsonDirPath, "ViewportTemplates.json")); List <ViewportTemplate> templates = JsonConvert.DeserializeObject <ViewportTemplate[]>(json).ToList(); if (versionedJsonPath == "") { ConfigManager.LogManager.LogInfo($"no ViewportTemplates_*.json file found that is applicable to selected DCS version {dcs.Version}"); } else { // read version specific changes and replace any entries by ModuleId string changesText = File.ReadAllText(versionedJsonPath); List <ViewportTemplate> changes = JsonConvert.DeserializeObject <ViewportTemplate[]>(changesText).ToList(); templates = templates.GroupJoin(changes, t => t.TemplateName, c => c.TemplateName, (original, applicableChanges) => applicableChanges.FirstOrDefault() ?? original).ToList(); } // get DCS location from the Helios utility that manages DCS install locations (have to use Profile Editor to configure it, either running dev build or start with --documents HeliosDev) string documentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "HeliosDev"); if (!Directory.Exists(documentPath)) { documentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Helios"); } HeliosInit.Initialize(documentPath, "EditViewports.log", LogLevel.Debug); ConfigManager.LogManager.LogInfo($"Editing viewport in DCS distribution {dcs.Path} of Version {dcs.Version}"); ConfigManager.LogManager.LogInfo($"Selected ViewportTemplates file {versionedJsonPath}"); PatchDestination destination = new PatchDestination(dcs); EditFilesInDestination(templates, destination); HeliosInit.OnShutdown(); }