Beispiel #1
0
        public static void OpenModsFolder(ModProjectData modProjectData)
        {
            Log.Here().Activity($"Attempting to open mods folder");

            if (MainData != null)
            {
                string startPath = Path.Combine(MainData.Settings.DOS2DEDataDirectory, "Mods");
                string directory = Path.Combine(Path.GetFullPath(startPath), modProjectData.FolderName);

                Log.Here().Activity($"Attempting to open directory {directory}");

                if (Directory.Exists(directory))
                {
                    Process.Start(directory);
                }
                else
                {
                    if (Directory.Exists(startPath))
                    {
                        Process.Start(startPath);
                    }
                    else
                    {
                        Log.Here().Error($"Mod directory for project {modProjectData.FolderName} does not exist!");
                    }
                }
            }
        }
Beispiel #2
0
 public static void OpenProjectFolder(ModProjectData modProjectData)
 {
     if (MainData != null)
     {
         string startPath = Path.Combine(MainData.Settings.DOS2DEDataDirectory, "Projects");
         string directory = Path.Combine(Path.GetFullPath(startPath), modProjectData.ProjectFolder);
         if (!Directory.Exists(directory))
         {
             directory = Path.Combine(Path.GetFullPath(startPath), modProjectData.ModuleInfo.Folder);                     // Imported projects
         }
         if (Directory.Exists(directory))
         {
             Process.Start(directory);
         }
         else
         {
             if (Directory.Exists(startPath))
             {
                 Process.Start(startPath);
             }
             else
             {
                 Log.Here().Error($"Projects directory for project {modProjectData.FolderName} does not exist!");
             }
         }
     }
 }
Beispiel #3
0
        private async Task <int> OnGitGenerationAsync()
        {
            Log.Here().Important("Generating git repositories for selected projects.");
            int total = Data.GitGenerationSettings.ExportProjects.Count;

            AppController.Main.Data.ProgressValueMax = total;

            //Log.Here().Activity($"[Progress] Amount per tick set to {amountPerTick}");

            AppController.Main.UpdateProgressMessage("Parsing selected projects...");

            var totalSuccess = 0;

            var sortedProjects = Data.GitGenerationSettings.ExportProjects.OrderBy(p => p.ProjectName).ToImmutableList();

            if (Data.GitGenerationSettings.ExportProjects.TryOperation(c => c.Clear()))
            {
                Data.GitGenerationSettings.ExportProjects.DoOperation(c => c.AddRange(sortedProjects));
            }

            for (var i = 0; i < total; i++)
            {
                AppController.Main.UpdateProgressTitle($"Generating Git Files... {(i)}/{total}");

                var project = Data.GitGenerationSettings.ExportProjects[i];

                AppController.Main.UpdateProgressMessage($"Generating git files for project {project.ProjectName}...");

                //Log.Here().Activity($"[Progress] Target percentage for this iteration is {targetPercentage}, work should increase it by {totalPercentageAmount}");

                ModProjectData modProjectData = (ModProjectData)project;

                var success = await GenerateGitFilesAsync(modProjectData, Data.GitGenerationSettings).ConfigureAwait(false);

                if (success)
                {
                    totalSuccess += 1;
                    AppController.Main.UpdateProgressLog($"Successfuly generated git repo for project {project.DisplayName}.");
                    Log.Here().Important("Git repository successfully generated for {0}.", project.DisplayName);
                }
                else
                {
                    AppController.Main.UpdateProgressLog($"Error generating git repo for project {project.DisplayName}.");
                    Log.Here().Error("Error generating git repository for {0}.", project.DisplayName);
                }

                AppController.Main.UpdateProgress(1);

                AppController.Main.UpdateProgressTitle($"Generating Git Files... {(i + 1)}/{total}");
            }

            AppController.Main.UpdateProgressTitle($"Generating Git Files... {total}/{total}");
            AppController.Main.UpdateProgressMessage("Finishing up...");
            AppController.Main.UpdateProgressLog("Git generation complete. We did it!");
            AppController.Main.FinishProgress();
            return(totalSuccess);
        }
        public static async Task <Unit> OpenLocalizationEditorForProject(ModProjectData modData)
        {
            Log.Here().Activity($"Opening locale editor for project {modData.DisplayName}");
            LocaleViewModel localizationData = new LocaleViewModel();

            LocaleEditorCommands.LoadSettings(_instance.ViewModel, localizationData);
            await LocaleEditorCommands.LoadLocalizationDataAsync(localizationData, _instance.ViewModel, modData);

            RxApp.MainThreadScheduler.Schedule(_ =>
            {
                _instance.OpenLocalizationEditorWithData(localizationData);
            });
            return(Unit.Default);
        }
Beispiel #5
0
        public static void OpenBackupFolder(ModProjectData modProjectData)
        {
            if (MainData != null)
            {
                string directory = Path.Combine(Path.GetFullPath(MainData.Settings.BackupRootDirectory), modProjectData.ProjectName);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                Process.Start(directory);
            }
            else
            {
                Log.Here().Error($"MainData is null!");
            }
        }
Beispiel #6
0
 public static void OpenGitFolder(ModProjectData modProjectData)
 {
     if (MainData != null)
     {
         string directory = modProjectData.GitData?.RepositoryPath;
         if (!String.IsNullOrEmpty(directory) && Directory.Exists(directory))
         {
             Process.Start(directory);
         }
         else
         {
             Process.Start(Path.GetFullPath(MainData.Settings.GitRootDirectory));
         }
     }
     else
     {
         Log.Here().Error($"MainData is null!");
     }
 }
Beispiel #7
0
        public void TestView()
        {
            /*
             * Data.UserKeywords.RemoveEmpty();
             *
             * for (int i = 0; i < 50; i++)
             * {
             *      string testStr = "test_" + i;
             *
             *      var tdata = new TemplateEditorData()
             *      {
             *              ID = testStr,
             *              Name = testStr
             *      };
             *      tdata.Init(Data);
             *      Data.Templates.Add(tdata);
             *
             *      var kdata = new KeywordData()
             *      {
             *              KeywordName = testStr,
             *              KeywordValue = ""
             *      };
             *      Data.UserKeywords.Keywords.Add(kdata);
             * }
             */

            Data.NewProjects.Add(new AvailableProjectViewData()
            {
                Name = "SJjjsjdiasjdiasidiahdisahdihaisdhddddddddddddddddddddddddddddddddddddddddiasdias"
            });

            for (var i = 0; i < 15; i++)
            {
                Data.NewProjects.Add(new AvailableProjectViewData()
                {
                    Name = "Project_" + i
                });
            }

            Data.ManagedProjects.Add(ModProjectData.Test("Test Project"));
            Data.ManagedProjects.Add(ModProjectData.Test("Test Project 2"));
        }
Beispiel #8
0
        public bool GenerateBackupFolder(ModProjectData modProject = null)
        {
            string projectBackupDirectory = Data.Settings.BackupRootDirectory;

            if (modProject != null)
            {
                projectBackupDirectory = Path.Combine(Data.Settings.BackupRootDirectory, modProject.ProjectName);
            }

            try
            {
                Directory.CreateDirectory(projectBackupDirectory);
                return(true);
            }
            catch (Exception ex)
            {
                MainWindow.FooterError("Error creating backup directory at {0}: {1}", projectBackupDirectory, ex.Message);
            }

            return(false);
        }
Beispiel #9
0
        private List <JunctionData> PrepareDirectories(ModProjectData project, List <string> DirectoryLayouts)
        {
            var sourceFolders = new List <JunctionData>();

            foreach (var directoryBaseName in DirectoryLayouts)
            {
                var projectSubdirectoryName = directoryBaseName.Replace("ProjectName", project.ProjectName).Replace("ProjectGUID", project.ModuleInfo.UUID);

                var junctionSourceDirectory = Path.Combine(Data.Settings.DOS2DataDirectory, projectSubdirectoryName);
                if (!Directory.Exists(junctionSourceDirectory))
                {
                    Log.Here().Important($"Directory {projectSubdirectoryName} doesn't exist. Creating directory.");
                    Directory.CreateDirectory(junctionSourceDirectory);
                }
                sourceFolders.Add(new JunctionData()
                {
                    SourcePath = junctionSourceDirectory,
                    BasePath   = projectSubdirectoryName
                });
            }
            return(sourceFolders);
        }
Beispiel #10
0
 public static void OpenEditorFolder(ModProjectData modProjectData)
 {
     if (MainData != null)
     {
         string startPath = Path.Combine(MainData.Settings.DOS2DEDataDirectory, "Editor/Mods");
         string directory = Path.Combine(Path.GetFullPath(startPath), modProjectData.FolderName);
         if (Directory.Exists(directory))
         {
             Process.Start(directory);
         }
         else
         {
             if (Directory.Exists(startPath))
             {
                 Process.Start(startPath);
             }
             else
             {
                 Log.Here().Error($"Editor directory for project {modProjectData.FolderName} does not exist!");
             }
         }
     }
 }
Beispiel #11
0
        public static List <ModProjectData> LoadModProjects(DOS2DEModuleData Data, bool clearExisting = false)
        {
            if (clearExisting)
            {
                Data.ModProjects.Clear();
                Log.Here().Important("Cleared mod project data.");
            }

            List <ModProjectData> newItems = new List <ModProjectData>();

            if (Data.Settings != null && !String.IsNullOrEmpty(Data.Settings.DOS2DEDataDirectory))
            {
                if (Directory.Exists(Data.Settings.DOS2DEDataDirectory))
                {
                    string projectsPath = Path.Combine(Data.Settings.DOS2DEDataDirectory, "Projects");
                    string modsPath     = Path.Combine(Data.Settings.DOS2DEDataDirectory, "Mods");

                    if (Directory.Exists(modsPath))
                    {
                        Log.Here().Activity("Loading DOS2 projects from mods directory at: {0}", modsPath);

                        DirectoryEnumerationFilters filters = new DirectoryEnumerationFilters()
                        {
                            InclusionFilter = (f) =>
                            {
                                return(!IgnoredFolders.Contains(f.FileName));
                            },
                        };

                        var modFolders = Directory.EnumerateDirectories(modsPath, DirectoryEnumerationOptions.Folders, filters, PathFormat.LongFullPath);

                        if (modFolders != null)
                        {
                            foreach (string modFolder in modFolders)
                            {
                                var modFolderName = Path.GetFileName(modFolder);
                                //Log.Here().Activity("Checking project mod folder: {0}", modFolderName);

                                var metaFilePath = Path.Combine(modFolder, "meta.lsx");
                                if (File.Exists(metaFilePath))
                                {
                                    //Log.Here().Activity("Meta file found for project {0}. Reading file.", modFolderName);

                                    ModProjectData modProjectData = new ModProjectData();
                                    modProjectData.LoadAllData(metaFilePath, projectsPath);

                                    //Log.Here().Activity("Finished reading meta files for mod: {0}", modProjectData.ModuleInfo.Name);

                                    if (!clearExisting)
                                    {
                                        var previous = Data.ModProjects.Items.FirstOrDefault(p => p.FolderName == modProjectData.FolderName);
                                        if (previous != null)
                                        {
                                            if (previous.DataIsNewer(modProjectData))
                                            {
                                                previous.UpdateData(modProjectData);
                                            }
                                        }
                                        else
                                        {
                                            newItems.Add(modProjectData);
                                        }
                                    }
                                    else
                                    {
                                        newItems.Add(modProjectData);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Log.Here().Error("Loading available projects failed. DOS2 data directory not found at {0}", Data.Settings.DOS2DEDataDirectory);
                }
            }

            return(newItems);
        }
Beispiel #12
0
        public static async Task <List <ModProjectData> > LoadModProjectsAsync(DOS2DEModuleData Data, bool clearExisting = false)
        {
            if (clearExisting)
            {
                Log.Here().Important("Clearing mod projects");
                if (Thread.CurrentThread.IsBackground)
                {
                    await Observable.Start(() =>
                    {
                        Data.ModProjects.Clear();
                        return(Unit.Default);
                    }, RxApp.MainThreadScheduler);
                }
                else
                {
                    Data.ModProjects.Clear();
                }
            }

            List <ModProjectData> newItems = new List <ModProjectData>();

            if (Data.Settings != null && !String.IsNullOrEmpty(Data.Settings.DOS2DEDataDirectory))
            {
                if (Directory.Exists(Data.Settings.DOS2DEDataDirectory))
                {
                    string projectsPath = Path.Combine(Data.Settings.DOS2DEDataDirectory, "Projects");
                    string modsPath     = Path.Combine(Data.Settings.DOS2DEDataDirectory, "Mods");

                    if (Directory.Exists(modsPath))
                    {
                        Log.Here().Activity($"Loading DOS2 projects from mods directory at: {modsPath}");

                        //DirectoryInfo modsRoot = new DirectoryInfo(modsPath);
                        //var modFolders = modsRoot.GetDirectories().Where(s => !IgnoredFolders.Contains(s.Name));

                        DirectoryEnumerationFilters filters = new DirectoryEnumerationFilters()
                        {
                            InclusionFilter = (f) =>
                            {
                                return(!IgnoredFolders.Contains(f.FileName));
                            },
                        };

                        //var modFolders = await Observable.Start(() =>
                        //{
                        //	return Directory.EnumerateDirectories(modsPath, DirectoryEnumerationOptions.Folders, filters, PathFormat.LongFullPath);
                        //}, RxApp.TaskpoolScheduler);

                        var modFolders = Directory.EnumerateDirectories(modsPath, DirectoryEnumerationOptions.Folders, filters, PathFormat.LongFullPath);

                        if (modFolders != null)
                        {
                            foreach (string modFolder in modFolders)
                            {
                                try
                                {
                                    var modFolderName = Path.GetFileName(modFolder);
                                    Log.Here().Activity($"Checking project mod folder: {modFolderName}");

                                    var metaFilePath = Path.Combine(modFolder, "meta.lsx");
                                    if (File.Exists(metaFilePath))
                                    {
                                        Log.Here().Activity($"Meta file found for project {modFolderName}. Reading file.");

                                        ModProjectData modProjectData = new ModProjectData();
                                        await modProjectData.LoadAllDataAsync(metaFilePath, projectsPath);

                                        Log.Here().Activity($"Finished reading meta files for mod: {modProjectData.ModuleInfo.Name}");

                                        if (!clearExisting)
                                        {
                                            var previous = Data.ModProjects.Items.FirstOrDefault(p => p.FolderName == modProjectData.FolderName);
                                            if (previous != null)
                                            {
                                                if (previous.DataIsNewer(modProjectData))
                                                {
                                                    if (Thread.CurrentThread.IsBackground)
                                                    {
                                                        await Observable.Start(() =>
                                                        {
                                                            previous.UpdateData(modProjectData);
                                                            return(Unit.Default);
                                                        }, RxApp.MainThreadScheduler);
                                                    }
                                                    else
                                                    {
                                                        previous.UpdateData(modProjectData);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                newItems.Add(modProjectData);
                                            }
                                        }
                                        else
                                        {
                                            newItems.Add(modProjectData);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log.Here().Error($"Error parsing mod folder ${modFolder}:");
                                    Log.Here().Error(ex.ToString());
                                }
                            }
                        }
                    }
                }
                else
                {
                    Log.Here().Error("Loading available projects failed. DOS2 data directory not found at {0}", Data.Settings.DOS2DEDataDirectory);
                }
            }

            return(newItems);
        }
        public static void LoadManagedProjects(DOS2ModuleData Data, bool ClearExisting = true)
        {
            if (Data.ManagedProjects == null)
            {
                Data.ManagedProjects = new ObservableImmutableList <ModProjectData>();
                BindingOperations.EnableCollectionSynchronization(Data.ManagedProjects, Data.ManagedProjectsLock);
            }
            else
            {
                if (ClearExisting)
                {
                    Data.ManagedProjects.DoOperation(data => data.Clear());
                    BindingOperations.EnableCollectionSynchronization(Data.ManagedProjects, Data.ManagedProjectsLock);
                }
            }

            string projectsAppDataPath = DefaultPaths.ModuleAddedProjectsFile(Data);

            if (Data.Settings != null && File.Exists(Data.Settings.AddedProjectsFile))
            {
                projectsAppDataPath = Data.Settings.AddedProjectsFile;
            }

            if (!String.IsNullOrEmpty(projectsAppDataPath) && File.Exists(projectsAppDataPath))
            {
                //projectsAppDataPath = Path.GetFullPath(projectsAppDataPath);
                try
                {
                    Data.ManagedProjectsData = JsonInterface.DeserializeObject <ManagedProjectsData>(projectsAppDataPath);
                }
                catch (Exception ex)
                {
                    Log.Here().Error("Error deserializing managed projects data at {0}: {1}", projectsAppDataPath, ex.ToString());
                }
            }


            if (Data.ManagedProjectsData == null)
            {
                Data.ManagedProjectsData = new ManagedProjectsData();
            }
            else
            {
                foreach (var project in Data.ManagedProjectsData.SavedProjects.Items)
                {
                    //var modProject = Data.ModProjects.Where(x => x.Name == project.Name && x.ModuleInfo.UUID == project.GUID).FirstOrDefault();
                    var modProject = Data.ModProjects.Where(x => x.UUID == project.UUID).FirstOrDefault();
                    if (modProject != null)
                    {
                        ModProjectData existingData = null;

                        if (!ClearExisting)
                        {
                            existingData = Data.ManagedProjects.Where(p => p.ProjectName == project.Name && p.UUID == project.UUID).FirstOrDefault();
                        }

                        if (ClearExisting || existingData == null)
                        {
                            Data.ManagedProjects.Add(modProject);

                            if (!String.IsNullOrWhiteSpace(project.LastBackupUTC))
                            {
                                DateTime lastBackup;

                                var success = DateTime.TryParse(project.LastBackupUTC, out lastBackup);
                                if (success)
                                {
                                    //Log.Here().Activity($"Successully parsed {modProject.LastBackup} to DateTime.");
                                    modProject.LastBackup = lastBackup.ToLocalTime();
                                }
                                else
                                {
                                    Log.Here().Error($"Could not convert {project.LastBackupUTC} to DateTime.");
                                }
                            }
                        }
                        else if (existingData != null)
                        {
                            existingData.ReloadData();
                        }
                    }
                }
            }
        }
Beispiel #14
0
        public async Task <FileCreationTaskResult> BackupProjectAsync(ModProjectData modProject, string OutputDirectory = "", BackupMode mode = BackupMode.Zip)
        {
            if (String.IsNullOrWhiteSpace(OutputDirectory))
            {
                OutputDirectory = Path.Combine(Path.GetFullPath(Data.Settings.BackupRootDirectory), modProject.ProjectName);
                Directory.CreateDirectory(OutputDirectory);
            }
            else
            {
                OutputDirectory = Path.GetFullPath(OutputDirectory);
            }

            string sysFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("/", "-");

            //Log.Here().Important($"System date format: {sysFormat}");

            string archiveName         = modProject.ProjectName + "_" + DateTime.Now.ToString(sysFormat + "_HH-mm-ss") + ".zip";
            string archivePath         = Path.Combine(OutputDirectory, archiveName);
            string gitProjectDirectory = "";

            /*
             * bool gitProjectDetected = false;
             *
             * if (!String.IsNullOrEmpty(Data.Settings.GitRootDirectory))
             * {
             *      gitProjectDirectory = Path.Combine(Data.Settings.GitRootDirectory, modProject.ProjectName);
             *      if (Directory.Exists(gitProjectDirectory))
             *      {
             *              gitProjectDirectory = Path.Combine(Data.Settings.GitRootDirectory, modProject.ProjectName);
             *              gitProjectDetected = true;
             *              AppController.Main.UpdateProgressLog("Git repository detected.");
             *      }
             * }
             */

            var sourceFolders = PrepareDirectories(modProject, Data.Settings.DirectoryLayouts);

            if (!modProject.GitGenerated)
            {
                AppController.Main.UpdateProgressLog("Creating zip archive from project folders...");
                //Log.Here().Activity($"Git project not found. Archiving project {modProject.ProjectName} from project folders directly.");
                return(await BackupGenerator.CreateArchiveFromRoot(Data.Settings.DOS2DataDirectory.Replace("/", "\\\\"), sourceFolders, archivePath, true, cancellationTokenSource.Token).ConfigureAwait(false));
            }
            else
            {
                gitProjectDirectory = Path.Combine(Data.Settings.GitRootDirectory, modProject.ProjectName);

                if (mode == BackupMode.GitArchive)
                {
                    AppController.Main.UpdateProgressLog("Running git archive command...");
                    var success = await GitGenerator.Archive(gitProjectDirectory, archivePath).ConfigureAwait(false);

                    return(success ? FileCreationTaskResult.Success : FileCreationTaskResult.Error);
                }
                else
                {
                    AppController.Main.UpdateProgressLog("Creating zip archive...");
                    return(await BackupGenerator.CreateArchiveFromRepo(gitProjectDirectory, Data.Settings.DOS2DataDirectory.Replace("/", "\\\\"), sourceFolders, archivePath, true, cancellationTokenSource.Token).ConfigureAwait(false));
                }
                //Seems to have a problem with junctions and long paths
                //return BackupGenerator.CreateArchiveFromRepo(gitProjectDirectory, archivePath);
            }
        }
Beispiel #15
0
        private async Task <bool> GenerateGitFilesAsync(ModProjectData modProject, GitGenerationSettings generationSettings)
        {
            if (modProject == null)
            {
                return(false);
            }
            //Log.Here().Activity($"[Progress] percentageIncrement is {percentageIncrement} / {endPercentage}");

            if (!string.IsNullOrEmpty(Data.Settings.GitRootDirectory))
            {
                string gitProjectRootDirectory = Path.Combine(Data.Settings.GitRootDirectory, modProject.ProjectName);

                AppController.Main.UpdateProgressLog("Creating git project directory...");

                var rootRepoDirectory = Directory.CreateDirectory(gitProjectRootDirectory);

                if (!Directory.Exists(gitProjectRootDirectory))
                {
                    Directory.CreateDirectory(gitProjectRootDirectory);
                }

                if (generationSettings.InitGit)
                {
                    AppController.Main.UpdateProgressLog("Initializing git repo...");

                    var author = Data.Settings.DefaultAuthor;
                    if (modProject.ModuleInfo != null && !String.IsNullOrWhiteSpace(modProject.ModuleInfo.Author))
                    {
                        author = modProject.ModuleInfo.Author;
                    }

                    var result = await GitGenerator.InitRepository(gitProjectRootDirectory, author);

                    if (result)
                    {
                        Log.Here().Activity("Created git repository for project ({0}) at {1}", modProject.ProjectName, gitProjectRootDirectory);
                    }
                    else
                    {
                        Log.Here().Error("Error creating git repository for project {0}.", modProject.ProjectName);
                    }
                }

                bool   commitGit     = false;
                string commitMessage = "";

                if (generationSettings.CreateJunctions)
                {
                    AppController.Main.UpdateProgressLog("Creating junctions...");

                    var sourceFolders = PrepareDirectories(modProject, Data.Settings.DirectoryLayouts);
                    var result        = GitGenerator.CreateJunctions(modProject.ProjectName, sourceFolders, Data);

                    if (result)
                    {
                        Log.Here().Activity("[{0}] Successfully created junctions.", modProject.ProjectName);
                        commitGit     = true;
                        commitMessage = "Junctioned project folders";
                    }
                    else
                    {
                        Log.Here().Error("[{0}] Problem creating junctions.", modProject.ProjectName);
                    }
                }

                if (generationSettings.TemplateSettings != null && generationSettings.TemplateSettings.Count > 0)
                {
                    AppController.Main.UpdateProgressLog("Generating templates...");

                    foreach (var templateSetting in generationSettings.TemplateSettings)
                    {
                        var templateData = Data.Templates.Where(t => t.Name == templateSetting.TemplateName).FirstOrDefault();
                        if (templateData != null)
                        {
                            if (templateSetting.Enabled)
                            {
                                string outputFilePath = Path.Combine(gitProjectRootDirectory, templateData.ExportPath);
                                string outputText     = GitGenerator.ReplaceKeywords(templateData.EditorText, modProject, MainAppData, Data);
                                if (!FileCommands.WriteToFile(outputFilePath, outputText))
                                {
                                    Log.Here().Error("[{0}] Failed to create template file at {1}", modProject.ProjectName, templateData.ExportPath);
                                }
                                else
                                {
                                    commitGit      = true;
                                    commitMessage += (", added " + templateData.Name);
                                }
                            }
                            else
                            {
                                Log.Here().Activity("[{0}] Skipping {1}", modProject.ProjectName, templateSetting.TemplateName);
                            }
                        }
                    }
                }

                if (generationSettings.SelectedLicense != LicenseType.None)
                {
                    AppController.Main.UpdateProgressLog("Generating license...");

                    string outputText = "";
                    if (generationSettings.SelectedLicense == LicenseType.Custom)
                    {
                        var customLicenseTemplate = Data.Templates.Where(t => t.Name == "LICENSE").FirstOrDefault();
                        if (customLicenseTemplate != null)
                        {
                            outputText = customLicenseTemplate.EditorText;
                        }
                    }
                    else
                    {
                        switch (generationSettings.SelectedLicense)
                        {
                        case LicenseType.MIT:
                            outputText = Properties.Resources.License_MIT;
                            break;

                        case LicenseType.Apache:
                            outputText = Properties.Resources.License_Apache;
                            break;

                        case LicenseType.GPL:
                            outputText = Properties.Resources.License_GPL;
                            break;
                        }
                    }

                    if (!String.IsNullOrEmpty(outputText))
                    {
                        outputText = GitGenerator.ReplaceKeywords(outputText, modProject, MainAppData, Data);
                    }

                    string licenseFile = Path.Combine(gitProjectRootDirectory, "LICENSE");

                    if (!FileCommands.WriteToFile(licenseFile, outputText))
                    {
                        Log.Here().Error("[{0}] Failed to write license template file at {1}", modProject.ProjectName, licenseFile);
                    }
                    else
                    {
                        commitGit      = true;
                        commitMessage += ", added license";
                    }
                }

                if (generationSettings.InitGit && commitGit)
                {
                    AppController.Main.UpdateProgressLog("Committing new files...");
                    var result = await GitGenerator.Commit(gitProjectRootDirectory, commitMessage);

                    if (result)
                    {
                        AppController.Main.UpdateProgressLog($"Successfully commited git repo for project {modProject.DisplayName}.");
                    }
                    else
                    {
                        AppController.Main.UpdateProgressLog($"Git repo failed to commit for project {modProject.DisplayName}.");
                    }
                }

                AppController.Main.UpdateProgressLog("Generating source control data file...");

                SourceControlData sourceControlData = new SourceControlData()
                {
                    ProjectName = modProject.ProjectName,
                    ProjectUUID = modProject.UUID
                };

                modProject.GitData = sourceControlData;

                FileCommands.Save.SaveSourceControlData(sourceControlData, gitProjectRootDirectory);

                AppController.Main.UpdateProgressAndMax(1);

                return(true);
            }
            //}
            //catch(Exception ex)
            //{
            //	Log.Here().Error($"Error generating git files: {ex.ToString()}");
            //}
            return(false);
        }
 public void LoadData(ModProjectData projectData)
 {
     initialVersionData = new ProjectVersionData(projectData.ModuleInfo.Version);
     SelectedProject    = projectData;
     DataContext        = SelectedProject;
 }
 public static void EditProjectVersion(ModProjectData projectData)
 {
     _instance.EditVersionWindow.LoadData(projectData);
     _instance.EditVersionWindow.Owner = _instance.MainWindow;
     _instance.EditVersionWindow.Show();
 }
Beispiel #18
0
        public void AddProjects(List <AvailableProjectViewData> selectedItems)
        {
            bool bSaveData = false;

            foreach (AvailableProjectViewData project in selectedItems)
            {
                Log.Here().Activity($"Adding project {project.Name} data to managed projects.");
                var modData = Data.ModProjects.Where(p => p.ProjectName == project.Name).FirstOrDefault();
                if (modData != null)
                {
                    //ManagedProjects.Add(new ProjectEntryData(modData.ProjectInfo, modData.ModInfo));
                    Data.ManagedProjects.Add(modData);
                    var availableProject = Data.NewProjects.Where(p => p.Name == project.Name).FirstOrDefault();
                    if (availableProject != null)
                    {
                        Data.NewProjects.Remove(availableProject);
                    }

                    if (Data.ManagedProjectsData.SavedProjects.Items.Any(p => p.UUID == modData.UUID))
                    {
                        if (modData.ProjectAppData == null)
                        {
                            ProjectAppData data = Data.ManagedProjectsData.SavedProjects.Items.Where(p => p.UUID == modData.ModuleInfo.UUID).FirstOrDefault();
                            if (data != null)
                            {
                                modData.ProjectAppData = data;

                                Log.Here().Activity($"Linked project {modData.ProjectName} data to managed project data.");
                            }
                        }
                    }
                    else
                    {
                        ProjectAppData data = new ProjectAppData()
                        {
                            Name          = modData.ProjectName,
                            UUID          = modData.ModuleInfo.UUID,
                            LastBackupUTC = null
                        };
                        Data.ManagedProjectsData.SavedProjects.AddOrUpdate(data);
                        modData.ProjectAppData = data;

                        Log.Here().Activity($"Added project {modData.DisplayName} to managed projects.");

                        bSaveData = true;
                    }
                }
                else
                {
#if DEBUG
                    Data.ManagedProjects.Add(ModProjectData.Test(project.Name));
#else
                    MainWindow.FooterError($"Error adding project {project.Name} to managed projects: Mod data doesn't exist.");
#endif
                }
            }

            Data.RaisePropertyChanged("NewProjects");

            if (bSaveData)
            {
                if (DOS2Commands.SaveManagedProjects(Data))
                {
                    MainWindow.FooterLog("Saved Managed Projects data to {0}.", Data.Settings.AddedProjectsFile);
                }
                else
                {
                    MainWindow.FooterError("Error saving Managed Projects data to {0}.", Data.Settings.AddedProjectsFile);
                }
            }
        }
 public static string CustomLocaleDirectory(DOS2DEModuleData Data, ModProjectData modProject)
 {
     return(Path.Combine(Data.Settings.GitRootDirectory, modProject.ProjectName, @"LocaleEditor\"));
 }
        public static void LoadModProjects(DOS2ModuleData Data, bool ClearPrevious = true)
        {
            if (Data.ModProjects == null)
            {
                Data.ModProjects = new ObservableImmutableList <ModProjectData>();
                BindingOperations.EnableCollectionSynchronization(Data.ModProjects, Data.ModProjectsLock);
            }
            else
            {
                if (ClearPrevious)
                {
                    Data.ModProjects.DoOperation(data => data.Clear());
                    BindingOperations.EnableCollectionSynchronization(Data.ModProjects, Data.ModProjectsLock);
                }
            }

            if (Data.Settings != null && !String.IsNullOrEmpty(Data.Settings.DOS2DataDirectory))
            {
                if (Directory.Exists(Data.Settings.DOS2DataDirectory))
                {
                    string projectsPath = Path.Combine(Data.Settings.DOS2DataDirectory, "Projects");
                    string modsPath     = Path.Combine(Data.Settings.DOS2DataDirectory, "Mods");

                    if (Directory.Exists(modsPath))
                    {
                        Log.Here().Activity("Loading DOS2 projects from mods directory at: {0}", modsPath);

                        DirectoryInfo modsRoot   = new DirectoryInfo(modsPath);
                        var           modFolders = modsRoot.GetDirectories().Where(s => !ignoredFolders.Contains(s.Name));

                        if (modFolders != null)
                        {
                            foreach (DirectoryInfo modFolderInfo in modFolders)
                            {
                                var modFolderName = modFolderInfo.Name;
                                Log.Here().Activity("Checking project mod folder: {0}", modFolderName);

                                var metaFile = modFolderInfo.GetFiles("meta.lsx").FirstOrDefault();
                                if (metaFile != null)
                                {
                                    Log.Here().Activity("Meta file found for project {0}. Reading file.", modFolderName);
                                    ModProjectData modProjectData = new ModProjectData(metaFile, projectsPath);
                                    Log.Here().Activity("Finished reading meta files for mod: {0}", modProjectData.ModuleInfo.Name);

                                    if (!ClearPrevious)
                                    {
                                        var previous = Data.ModProjects.Where(p => p.FolderName == modProjectData.FolderName).FirstOrDefault();
                                        if (previous != null)
                                        {
                                            if (previous.DataIsNewer(modProjectData))
                                            {
                                                previous.UpdateData(modProjectData);
                                            }
                                        }
                                        else
                                        {
                                            Data.ModProjects.DoOperation(data => data.Add(modProjectData));
                                        }
                                    }
                                    else
                                    {
                                        Data.ModProjects.DoOperation(data => data.Add(modProjectData));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Log.Here().Error("Loading available projects failed. DOS2 data directory not found at {0}", Data.Settings.DOS2DataDirectory);
                }
            }
        }