Beispiel #1
0
        private NPath GrabZipFromResources()
        {
            installDetails.ZipFile.DeleteIfExists();

            AssemblyResources.ToFile(ResourceType.Generic, "octorun.zip", installDetails.BaseZipPath, environment);

            return(installDetails.ZipFile);
        }
        public void InitializeRepository()
        {
            isBusy = true;
            progress.UpdateProgress(0, 100, "Initializing...");
            var thread = new Thread(() =>
            {
                var success = true;
                try
                {
                    var targetPath = NPath.CurrentDirectory;

                    var gitignore       = targetPath.Combine(".gitignore");
                    var gitAttrs        = targetPath.Combine(".gitattributes");
                    var assetsGitignore = targetPath.Combine("Assets", ".gitignore");

                    var filesForInitialCommit = new List <string> {
                        gitignore, gitAttrs, assetsGitignore
                    };

                    GitClient.Init().RunSynchronously();
                    progress.UpdateProgress(10, 100, "Initializing...");

                    ConfigureMergeSettings();
                    progress.UpdateProgress(20, 100, "Initializing...");

                    GitClient.LfsInstall().RunSynchronously();
                    progress.UpdateProgress(30, 100, "Initializing...");

                    AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
                    AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
                    assetsGitignore.CreateFile();
                    GitClient.Add(filesForInitialCommit).RunSynchronously();
                    progress.UpdateProgress(60, 100, "Initializing...");
                    GitClient.Commit("Initial commit", null).RunSynchronously();
                    progress.UpdateProgress(70, 100, "Initializing...");
                    Environment.InitializeRepository();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "A problem ocurred initializing the repository");
                    progress.UpdateProgress(90, 100, "Failed to initialize repository");
                    success = false;
                }

                if (success)
                {
                    progress.UpdateProgress(90, 100, "Initializing...");
                    RestartRepository();
                    TaskManager.RunInUI(InitializeUI);
                    UsageTracker.IncrementProjectsInitialized();
                    progress.UpdateProgress(100, 100, "Initialized");
                }
                isBusy = false;
            });

            thread.Start();
        }
Beispiel #3
0
        public static Package Load(IEnvironment environment, UriString packageFeed)
        {
            Package package  = null;
            var     filename = packageFeed.Filename.ToNPath();

            if (!filename.IsInitialized || filename.IsRoot)
            {
                return(package);
            }
            var   key  = filename.FileNameWithoutExtension + "_updatelastCheckTime";
            var   now  = DateTimeOffset.Now;
            NPath feed = environment.UserCachePath.Combine(packageFeed.Filename);

            if (!feed.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date)
            {
                feed = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath)
                       .Catch(ex =>
                {
                    LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                })
                       .RunWithReturn(true);

                if (feed.IsInitialized)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!feed.IsInitialized)
            {
                // try from assembly resources
                feed = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment);
            }

            if (feed.IsInitialized)
            {
                try
                {
                    package = feed.ReadAllText().FromJson <Package>(true, false);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }
            return(package);
        }
Beispiel #4
0
        private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
        {
            if (!state.GitZipExists)
            {
                AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
            }
            state.GitZipExists = installDetails.GitZipPath.FileExists();

            if (!state.GitLfsZipExists)
            {
                AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
            }
            state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
            installationTask.UpdateProgress(30, 100);
            return(state);
        }
Beispiel #5
0
        public ITask InitializeRepository()
        {
            //Logger.Trace("Running Repository Initialize");

            var targetPath = NPath.CurrentDirectory;

            var unityYamlMergeExec = Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);

            var yamlMergeCommand = Environment.IsWindows
                ? $@"'{unityYamlMergeExec}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED"""
                : $@"'{unityYamlMergeExec}' merge -p '$BASE' '$REMOTE' '$LOCAL' '$MERGED'";

            var gitignore       = targetPath.Combine(".gitignore");
            var gitAttrs        = targetPath.Combine(".gitattributes");
            var assetsGitignore = targetPath.Combine("Assets", ".gitignore");

            var filesForInitialCommit = new List <string> {
                gitignore, gitAttrs, assetsGitignore
            };

            var task =
                GitClient.Init()
                .Then(GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local))
                .Then(GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local))
                .Then(GitClient.LfsInstall())
                .ThenInUI(SetProjectToTextSerialization)
                .Then(new ActionTask(CancellationToken, _ => {
                AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
                AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);

                assetsGitignore.CreateFile();
            }))
                .Then(GitClient.Add(filesForInitialCommit))
                .Then(GitClient.Commit("Initial commit", null))
                .Then(_ =>
            {
                Environment.InitializeRepository();
                RestartRepository();
            })
                .ThenInUI(() =>
            {
                TaskManager.Run(UsageTracker.IncrementNumberOfProjectsInitialized);
                InitializeUI();
            });

            return(task);
        }
Beispiel #6
0
        private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
        {
            if (!state.GitZipExists && !state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
            {
                AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
            }
            state.GitZipExists = installDetails.GitZipPath.FileExists();

            if (state.GitLfsInstallationPath != installDetails.GitLfsInstallationPath)
            {
                return(state);
            }

            if (!state.GitLfsZipExists && !state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
            {
                AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
            }
            state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
            return(state);
        }
Beispiel #7
0
        private GitInstallationState VerifyZipFiles(GitInstallationState state)
        {
            var md5 = AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", installDetails.ZipPath, environment);

            if (!md5.FileExists() || (installDetails.GitZipPath.FileExists() && !Utils.VerifyFileIntegrity(installDetails.GitZipPath, md5)))
            {
                installDetails.GitZipPath.DeleteIfExists();
            }
            state.GitZipExists = installDetails.GitZipPath.FileExists();

            md5 = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", installDetails.ZipPath, environment);
            // check whether the git-lfs zip file exists and is valid
            if (!md5.FileExists() || (installDetails.GitLfsZipPath.FileExists() && !Utils.VerifyFileIntegrity(installDetails.GitLfsZipPath, md5)))
            {
                installDetails.GitLfsZipPath.DeleteIfExists();
            }
            state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
            installationTask.UpdateProgress(20, 100);
            return(state);
        }
Beispiel #8
0
 private NPath GrabZipFromResources()
 {
     return(AssemblyResources.ToFile(ResourceType.Generic, "octorun.zip", installDetails.BaseZipPath, environment));
 }
Beispiel #9
0
        public Task <bool> SetupGitLfsIfNeeded(NPath tempPath, IProgress <float> zipFileProgress = null,
                                               IProgress <long> estimatedDurationProgress        = null)
        {
            logger.Trace("SetupGitLfsIfNeeded");

            cancellationToken.ThrowIfCancellationRequested();

            if (IsGitLfsExtracted())
            {
                logger.Trace("Already extracted {0}, returning", GitLfsExecutablePath);
                return(TaskEx.FromResult(false));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, GitLfsZipFile, tempPath, environment);

            if (!archiveFilePath.FileExists())
            {
                logger.Warning("Archive \"{0}\" missing", archiveFilePath.ToString());

                archiveFilePath = environment.ExtensionInstallPath.Combine(archiveFilePath);
                if (!archiveFilePath.FileExists())
                {
                    logger.Warning("Archive \"{0}\" missing, returning", archiveFilePath.ToString());
                    return(TaskEx.FromResult(false));
                }
            }

            cancellationToken.ThrowIfCancellationRequested();

            var unzipPath = tempPath.Combine("git-lfs");

            try
            {
                logger.Trace("Extracting \"{0}\" to \"{1}\"", archiveFilePath, unzipPath);

                extractCallback(archiveFilePath, unzipPath, cancellationToken, zipFileProgress,
                                estimatedDurationProgress);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error Extracting Archive:\"{0}\" OutDir:\"{1}\"", archiveFilePath, tempPath);
                return(TaskEx.FromResult(false));
            }

            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                var unzippedGitLfsExecutablePath = unzipPath.Combine(GitLfsExecutable);
                logger.Trace("Copying \"{0}\" to \"{1}\"", unzippedGitLfsExecutablePath, GitLfsExecutablePath);

                unzippedGitLfsExecutablePath.Copy(GitLfsExecutablePath);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error Copying git-lfs Source:\"{0}\" Destination:\"{1}\"", unzipPath, GitLfsExecutablePath);
                return(TaskEx.FromResult(false));
            }
            unzipPath.DeleteIfExists();
            return(TaskEx.FromResult(true));
        }