예제 #1
0
        /// <summary>
        /// Downloads config from specified Uri and compares version to runtime exe version.  Starts update if update is marked as 'Mandatory'.
        /// </summary>
        public PatchStatus InitializePatchStatus()
        {
            PatchStatus result = new PatchStatus();

            Status = result;

            //assemble accurate path and file names, check for exe existence, bail if not present
            RuntimeExeInfo rei = new RuntimeExeInfo(_settings.RuntimeExe);

            result.ExeInfo = rei;

            if (!rei.Exists)
            {
                SetLogMessage("Could not find file {0}; aborting.", true, rei.FullPath);
                return(result);
            }

            //this will always return a valid config, but it will be empty on load failure (CurrVer = 0.0.0.0)
            UpdateConfig uc = LoadConfig();

            result.PatchIsMandatory = uc.IsMandatory;

            if (uc.CurrentVer > rei.Version)
            {
                SetLogMessage("Current version is {0}, getting new version: {1}", rei.Version, uc.CurrentVersion);

                if (uc.LastMandatoryVer > rei.Version)
                {
                    result.PatchIsMandatory = true;
                    SetLogMessage("Current patch is Mandatory due to version age: {0} / {1}", rei.Version, uc.LastMandatoryVer);
                }

                #region ensure patch folders exist
                string downloadFolderRoot = _settings.DownloadFolder;
                if (!Directory.Exists(downloadFolderRoot))
                {
                    Directory.CreateDirectory(downloadFolderRoot);
                }

                Uri    patchUri = new Uri(uc.PatchUri);
                string fileName = patchUri.Segments[patchUri.Segments.Length - 1];

                string patchFolder = Path.Combine(downloadFolderRoot, Path.GetFileNameWithoutExtension(fileName));
                if (!Directory.Exists(patchFolder))
                {
                    Directory.CreateDirectory(patchFolder);
                }
                #endregion

                //download/copy the patch file
                string patchFilePath = Path.Combine(patchFolder, fileName);
                result.PatchIsValid = PatchFileIsValid(patchFilePath, uc.PatchSizeBytes);
                if (!result.PatchIsValid)
                {
                    result.PatchIsValid = GetPatchFile(patchUri, patchFilePath, uc.PatchSizeBytes);
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Helper method for InstallExistingPatches(string processName, string rootUnzipPath) that uses default pathing
        /// </summary>
        public void InstallExistingPatches()
        {
            //assemble accurate path and file names, check for exe existence, bail if not present
            RuntimeExeInfo rei = new RuntimeExeInfo(_settings.RuntimeExe);

            if (!rei.Exists)
            {
                SetLogMessage("Could not find file {0}; aborting.", true, rei.FullPath);
            }
            else
            {
                SetLogMessage("Starting installation of existing patches.");
                InstallExistingPatches(rei.FullPath, rei.FolderPath);
            }
        }