Exemple #1
0
        private async Task <FileCreationTaskResult> BackupTest()
        {
            if (Directory.Exists(debugWindowData.BackupFolderPath))
            {
                string sysFormat   = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("/", "-");
                string archiveName = "DebugBackupTest_" + DateTime.Now.ToString(sysFormat + "_HH-mm-ss") + ".zip";
                Directory.CreateDirectory("Debug");
                string outputFilePath = @"Debug\" + archiveName;
                return(await BackupGenerator.CreateArchiveFromDirectory(debugWindowData.BackupFolderPath.Replace("/", "\\\\"), outputFilePath, true, Token.Token));
            }

            return(FileCreationTaskResult.Error);
        }
Exemple #2
0
        public async Task <BackupResult> BackupProjectAsync(DefaultProjectData modProject, string OutputDirectory = "", BackupMode mode = BackupMode.Zip, int totalPercentageAmount = -1)
        {
            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.");
             *      }
             * }
             */

            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.CreateArchiveFromDirectory(modProject.Directory, archivePath, true).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 ? BackupResult.Success : BackupResult.Error);
                }
                else
                {
                    AppController.Main.UpdateProgressLog("Creating zip archive...");
                    return(await BackupGenerator.CreateArchiveFromDirectory(modProject.Directory, archivePath, true).ConfigureAwait(false));
                }
                //Seems to have a problem with junctions and long paths
                //return BackupGenerator.CreateArchiveFromRepo(gitProjectDirectory, archivePath);
            }
        }