Пример #1
0
        /// <summary>
        /// Create a new instance of this class
        /// </summary>
        /// <param name="input">The path to the folder containing the base files</param>
        /// <param name="output">The path to the folder to put the finished ready to upload files to</param>
        public CreateDownloadableManager(string input, string output)
        {
            _inputFolder  = input;
            _outputFolder = output;

            _updateConfiguration = new UpdaterConfigJson();
        }
Пример #2
0
        /// <summary>
        /// This is the real function for the update process the public functions just refer to this one
        /// </summary>
        /// <param name="isAsync">This can be set to true to send out event updates</param>
        private void PerformUpdate(bool isAsync = false)
        {
            if (!_readyForUpdate)
            {
                TriggerErrorEvent(ErrorEnum.warning, "Not ready for update yet!");
                return;
            }

            UpdaterConfigJson updaterConfig = GetUpdaterConfigJson();

            if (updaterConfig == null)
            {
                return;
            }

            List <UpdateableFile> onlineFiles = updaterConfig.Files;
            int currentCount = 0;

            _maxUpdateStatus = onlineFiles.Count;
            foreach (UpdateableFile currentServerFile in onlineFiles)
            {
                string currentFile   = _settings.MainProjectFolder + "\\" + _data.Name + "\\" + currentServerFile.Name;
                string localChecksum = currentFile.GetChecksum();

                if (localChecksum != currentServerFile.Checksum)
                {
                    DownloadFile(_data.HomeUrl + "/" + _projectManager.LauncherSettings.DownloadMainFolder + "/" + currentServerFile.Name, currentServerFile.Name);
                    if (isAsync)
                    {
                        _asyncUpdateProvider.ReportProgress(currentCount, currentServerFile);
                    }
                }
                currentCount++;
            }
        }
Пример #3
0
        /// <summary>
        /// This function will save the update info file
        /// </summary>
        private void SaveUpdateInfo()
        {
            string dataToSave = JsonConvert.SerializeObject(_updateConfiguration, Formatting.Indented);

            _updateConfiguration = new UpdaterConfigJson();
            string fileName = _outputFolder + "\\" + "UpdateInfo.json";

            using (StreamWriter writer = new StreamWriter(fileName))
            {
                writer.Write(dataToSave);
            }
        }
Пример #4
0
        /// <summary>
        /// This will download the file list from the server containing the filename and the checksum
        /// </summary>
        /// <returns>Returns the server instance of the update list</returns>
        private UpdaterConfigJson GetUpdaterConfigJson()
        {
            string updateInfo = _projectManager.UpdateInfo.DownloadString();

            UpdaterConfigJson updaterConfig = null;

            try
            {
                updaterConfig = JsonConvert.DeserializeObject <UpdaterConfigJson>(updateInfo);
            }
            catch (Exception)
            {
                return(null);
            }
            return(updaterConfig);
        }
Пример #5
0
        /// <summary>
        /// This functions checks if there is a local file differenting from the server files
        /// </summary>
        /// <returns>Returns true if one or more checksums are not identical with the server</returns>
        public bool UpdateAvailable()
        {
            UpdaterConfigJson serverConfig = GetUpdaterConfigJson();

            if (serverConfig == null)
            {
                return(false);
            }
            string baseFolder = _settings.MainProjectFolder + "\\" + _data.Name;

            foreach (UpdateableFile currentServerFile in serverConfig.Files)
            {
                string localFile = baseFolder + "\\" + currentServerFile.Name;


                string localChecksum = localFile.GetChecksum();
                if (localChecksum != currentServerFile.Checksum)
                {
                    return(true);
                }
            }

            return(false);
        }