Beispiel #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);
        }
Beispiel #2
0
        public void CompareDownloadInstall()
        {
            PatchStatus result = InitializePatchStatus();

            //run it if required
            if (result.PatchIsValid && result.PatchIsMandatory)
            {
                InstallExistingPatches(result.ExeInfo.FullPath, result.ExeInfo.FolderPath);
            }
        }