예제 #1
0
        public static RepoVersion Build(Patchalyzer patchalyzer, SemVersion version, string path, string name, string changelog = "", long releaseDate = -1)
        {
            RepoConfig config   = patchalyzer.GetRepoConfig();
            string     repoPath = patchalyzer.GetRepoPath();

            // If releaseDate is missing then set it to the current time.
            if (releaseDate == -1)
            {
                releaseDate = DateTimeOffset.Now.ToUnixTimeSeconds();
            }

            RepoVersion repoVersion = new RepoVersion
            {
                Name        = name,
                ReleaseDate = releaseDate,
                Changelog   = changelog
            };

            bool isUpdate = false;

            // Check if a previous version exists
            if (config.LatestVersion != null && config.Versions.ContainsKey(config.LatestVersion))
            {
                SemVersion latestVersion;
                if (SemVersion.TryParse(config.LatestVersion, out latestVersion))
                {
                    isUpdate = (latestVersion < version);
                }
            }

            repoVersion.Files        = isUpdate ? AddFiles(repoPath, version, path, config.LatestVersion, config.Versions[config.LatestVersion]) : AddFiles(repoPath, version, path);
            repoVersion.DeletedFiles = isUpdate ? GetDeletedFiles(repoVersion.Files, config.Versions[config.LatestVersion].Files) : new List <string>();

            return(repoVersion);
        }
예제 #2
0
파일: Bootstrap.cs 프로젝트: stuart2w/SAW
        public static void Main(string[] cmdArgs)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                Strings.Load();                 // <--- leave breakpoint here in case of starting wrong project by accident!
                Globals.Root.Log("Initialised bootstrap");

                string parameter = "";
                if (cmdArgs != null && (cmdArgs.Length - 1) >= 0)
                {
                    parameter = cmdArgs[0];                     // version number
                }
#if DEBUG
                parameter = "0.15.0";
#endif
                // can be followed by /Auto (checked in frmUpdate)
                if (parameter == "")
                {
                    MessageBox.Show(Strings.Item("Install_NoDirect"));
                    // the application must have been run directly by the user
                    return;
                }
                Globals.Root.Log("Parameter = " + parameter);

                Version = parameter;
                string versionFile = Globals.Root.UpdateFolder + "\\" + Version + ".repo";
                if (!File.Exists(versionFile))
                {
                    MessageBox.Show("Cannot locate index file: " + versionFile);
                    return;
                }
                Globals.Root.Log("Version file exists");
                RepoVersion version = RepoList.LoadVersionFile(versionFile);
                if (version.Signature != "" && !string.Equals(version.Signature, version.CalculateSignature(), StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show("Update index cannot be used, it has an invalid signature.   The index that has been downloaded is not a true copy of the index.");
                    return;
                }
                version.SetLocalPath(Globals.Root.InternalFolder + "\\");
                version.SetLocalPath("%shared%", Globals.Root.SharedFolder + "\\");
                Globals.Root.Log("Opening form");
                frmUpdate form = new frmUpdate(version);
                Application.Run(form);
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #3
0
 public void UpdateSixSyncState(ISupportModding game)
 {
     SetSharedState(game);
     SetSixSyncPaths();
     _sixSyncRepoExists  = DoesRepoExist();
     _isValidSixSync     = IsValidSixSync();
     _isValidSixSyncPack = IsPackValidSixSync();
     _sixSyncVersionInfo = _isValidSixSync ? TryReadRepoFile(_repoYamlFile) : null;
     try {
         DesiredRevision = _mod.Version;
         LatestRevision  = _mod.Version;
         Guid            = GetSixSyncGuid();
         Revision        = GetSixSyncRevision(false);
         State           = !ModMatchesActiveGame(game) ? ContentState.Incompatible : GetSixSyncModState();
     } finally {
         _sixSyncVersionInfo = null;
     }
 }
예제 #4
0
 public void UpdateSynqState(ISupportModding game, PackageItem package)
 {
     if (package == null)
     {
         throw new ArgumentNullException(nameof(package));
     }
     _package = package;
     SetSharedState(game);
     _isValidSixSync     = false;
     _isValidSixSyncPack = false;
     _sixSyncRepoExists  = false;
     _sixSyncVersionInfo = null;
     _package.UpdateCurrentVersion();
     Revision        = GetSynqRevision();
     DesiredRevision = GetSynqDesiredRevision();
     LatestRevision  = GetSynqLatestRevision();
     State           = !ModMatchesActiveGame(game) ? ContentState.Incompatible : GetSynqModState();
     //Cheat.PublishDomainEvent(new ModInfoChangedEvent(new ModInfo(_mod)));
 }
예제 #5
0
        public TaskResult ValidatePatchProcess()
        {
            var result = new TaskResult()
            {
                IsValid = true
            };

            // pull request merged?
            if (!AssemblyHelper.PullRequest.Merged)
            {
                result.AddError(String.Format("Pull Request {0} has not been merged yet.", AssemblyHelper.PullRequest.Id));
                // no further validation may be done. Bail...
                return(result);
            }

            try
            {
                // repo at the correct version?
                if (!ValidatePatchVersion())
                {
                    result.AddError(String.Format("Repo version, {0} - {1}, does match patch target version(s), {2} - {3}.", BranchVersionHelper.CurrentBranch.Name, RepoVersion.ToString(), this.Branch.Name, PatchTargetVersion.ToString()));
                }
                //if (PatchTargetVersion.Build == -1 && PatchTargetVersion.Revision == -1)
                //{
                //    if (RepoVersion.Major != PatchTargetVersion.Major || RepoVersion.Minor != PatchTargetVersion.Minor)
                //    {
                //        result.AddError(String.Format("Repo version, {0}, does match patch target version, {1}.", RepoVersion.ToString(), PatchTargetVersion.ToString()));
                //        // no further validation may be done. Bail...
                //        return result;
                //    }
                //    else
                //    {
                //        PatchTargetVersion = RepoVersion;
                //    }
                //}

                _sourceAssemblies = GetSourceAssemblies();
                // assembly exists?
                foreach (var assemblyFileName in _sourceAssemblies)
                {
                    if (!File.Exists(assemblyFileName.FullName))
                    {
                        result.AddError(String.Format("Built assembly {0} is not found.", assemblyFileName.FullName));
                    }
                    else
                    {
                        // versions correct?
                        var    versInfo       = FileVersionInfo.GetVersionInfo(assemblyFileName.FullName);
                        String fileVersion    = versInfo.FileVersion;
                        String productVersion = versInfo.ProductVersion;

                        //example for own display version string, built of the four version parts:
                        String myVers = String.Format("V{0}.{1}.{2} build {3}", versInfo.FileMajorPart, versInfo.FileMinorPart,
                                                      versInfo.FileBuildPart, versInfo.FilePrivatePart);

                        Console.WriteLine("{0}: File Version:{1}; Product Version:{2}; myVers:{3}; IsDebug:{4}", assemblyFileName.FullName, fileVersion, productVersion, myVers, versInfo.IsDebug);
                        if (RepoVersion.ToString() != fileVersion)
                        {
                            result.AddError(String.Format("Built assembly {0} is at version {1}, patching to version {2}.", assemblyFileName, fileVersion, RepoVersion.ToString()));
                        }

                        // built since request made?
                        var      binAssemblyFileInfo     = new FileInfo(assemblyFileName.FullName);
                        DateTime binAssemblyLastModified = binAssemblyFileInfo.LastWriteTime;
                        if (BuildTimestampLimit > binAssemblyLastModified)
                        {
                            result.AddError(String.Format("Built assembly {0} is out of date. Last build was {1}, build cutoff timestamp is {2}.", assemblyFileName.FullName, binAssemblyLastModified, BuildTimestampLimit));
                        }

                        // debug?
                        if (versInfo.IsDebug)
                        {
                            result.AddError(String.Format("Built assembly {0} is a DEBUG assembly.", assemblyFileName.FullName));
                        }

                        var targetAssembly = Path.Combine(PatchFolder, assemblyFileName.Name);
                        if (File.Exists(targetAssembly))
                        {
                            result.AddDebug(String.Format("Assembly {0} exists in patch folder.", targetAssembly));
                            // target assembly not newer than source assembly?
                            var patchFolderAssemblyFileInfo = new FileInfo(targetAssembly);

                            if (binAssemblyLastModified < patchFolderAssemblyFileInfo.LastWriteTime)
                            {
                                result.AddError(String.Format("Built assembly {0} is out of date. Assembly currently in Patch folder has more recent build timestamp, {1}.", assemblyFileName.Name, binAssemblyLastModified, patchFolderAssemblyFileInfo.LastWriteTime));
                            }
                            // target assembly build timestamp same as source? (same build time and version)
                            if (binAssemblyLastModified == patchFolderAssemblyFileInfo.LastWriteTime)
                            {
                                result.AddError(String.Format("Assembly {0} has the same build timestamp in Patch and Bin folders.", assemblyFileName.Name));
                            }
                        }

                        // confirm commit(s) in current branch.


                        if (!Directory.Exists(AssemblyBackupFolder))
                        {
                            var backupInfo = Directory.CreateDirectory(AssemblyBackupFolder);
                            if (null == backupInfo)
                            {
                                result.AddError(String.Format("Error creating backup directory {0}.", AssemblyBackupFolder));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddError(ex.ToString());
            }
            return(result);
        }
예제 #6
0
파일: frmUpdate.cs 프로젝트: stuart2w/SAW
 public frmUpdate(RepoVersion version)
 {
     // the signature of the version has already been verified
     m_Version = version;
     InitializeComponent();
 }
예제 #7
0
        private static List <RepoFile> AddFiles(string repoPath, SemVersion version, string path, string previousVersionNumber = null, RepoVersion previousVersion = null)
        {
            string previousVersionPath = null;

            if (previousVersionNumber != null)
            {
                previousVersionPath = Path.Combine(repoPath, previousVersionNumber);
            }

            Console.WriteLine("Adding files from " + path + ((previousVersionPath != null) ? " | Comparing them to: " + previousVersionPath : ""));
            List <RepoFile> files = new List <RepoFile>();

            var fileList = new List <string>();

            FileUtil.GetFiles(path, ref fileList);

            foreach (var file in fileList)
            {
                var repoFile = new RepoFile
                {
                    Path     = FileUtil.GetRelativePath(path, file).Replace("\\", "/"),
                    Checksum = Checksum.GetSHA1Sum(file)
                };

                string exportPath = Path.Combine(repoPath, version.ToString(), repoFile.Path);

                if (previousVersion != null)
                {
                    var oldRepoFile = previousVersion.GetFile(repoFile.Path);

                    if (oldRepoFile?.Checksum == repoFile.Checksum)
                    {
                        // Flag the file as unchanged to consolidate repo space
                        repoFile.UnchangedSince = oldRepoFile.UnchangedSince ?? previousVersionNumber;
                    }
                    else
                    {
                        Console.WriteLine("\tAdding file " + repoFile.Path);

                        // Copy the entire file if a previous version doesn't exist.
                        Directory.CreateDirectory(Path.GetDirectoryName(exportPath));
                        File.Copy(file, exportPath);

                        // Generate patches
                        string prevPath;
                        if (oldRepoFile?.UnchangedSince != null)
                        {
                            Console.WriteLine("\t\tUnchanged since " + oldRepoFile.UnchangedSince);
                            prevPath = Path.Combine(Path.Combine(repoPath, oldRepoFile.UnchangedSince), repoFile.Path);
                        }
                        else
                        {
                            prevPath = Path.Combine(previousVersionPath, repoFile.Path);
                        }

                        if (File.Exists(prevPath))
                        {
                            var origChecksum = Checksum.GetSHA1Sum(prevPath);
                            // Don't generate a patch for an unchanged file
                            if (origChecksum != repoFile.Checksum)
                            {
                                Console.WriteLine("\t\tGenerating patch...");

                                repoFile.PatchSourceChecksum = origChecksum;
                                // Create the BsDiff patch
                                using (FileStream patchFileStream =
                                           new FileStream(exportPath + ".patch", FileMode.Create))
                                    BsDiff.Create(File.ReadAllBytes(exportPath), File.ReadAllBytes(prevPath),
                                                  patchFileStream);
                                // Get checksum of the patch
                                repoFile.PatchChecksum = Checksum.GetSHA1Sum(exportPath + ".patch");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\tAdding file " + repoFile.Path);
                    // Copy the entire file if a previous version doesn't exist.
                    Directory.CreateDirectory(Path.GetDirectoryName(exportPath));
                    File.Copy(file, exportPath);
                }


                files.Add(repoFile);
            }

            return(files);
        }