示例#1
0
 public ConfigLoader(string updatePath, UpdaterSettings settings)
 {
     _settings = settings;
     DirectoryInfo path = new DirectoryInfo(String.Format("{1}{0}NETUpdater{0}NETUpdater{0}LocalConfig{0}",
             Path.DirectorySeparatorChar,
             Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)));
     if (!path.Exists) path.Create();
     _filename = String.Format("{1}{0}NETUpdater{0}NETUpdater{0}LocalConfig{0}{2}",
             Path.DirectorySeparatorChar,
             Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
             _settings.LocalConfigName);
     localConfigs = new List<Config>();
     document = new XmlDocument();
     string[] str = Assembly.GetExecutingAssembly().GetManifestResourceNames();
     Stream _schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NETUpdater.Update.ConfigSchema.xsd");
     XmlReader _schemaReader = XmlReader.Create(_schemaStream);
     document.Schemas.Add(SchemaTargetName, _schemaReader);
     document.Schemas.Compile();
 }
示例#2
0
        public ConfigLoader(string updatePath, UpdaterSettings settings)
        {
            _settings = settings;
            DirectoryInfo path = new DirectoryInfo(String.Format("{1}{0}NETUpdater{0}NETUpdater{0}LocalConfig{0}",
                                                                 Path.DirectorySeparatorChar,
                                                                 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)));

            if (!path.Exists)
            {
                path.Create();
            }
            _filename = String.Format("{1}{0}NETUpdater{0}NETUpdater{0}LocalConfig{0}{2}",
                                      Path.DirectorySeparatorChar,
                                      Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                      _settings.LocalConfigName);
            localConfigs = new List <Config>();
            document     = new XmlDocument();
            string[]  str           = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            Stream    _schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NETUpdater.Update.ConfigSchema.xsd");
            XmlReader _schemaReader = XmlReader.Create(_schemaStream);

            document.Schemas.Add(SchemaTargetName, _schemaReader);
            document.Schemas.Compile();
        }
示例#3
0
        private void UpdateAsync()
        {
            AppArgument updatePath = new AppArgument()
            {
                Name = "--path", Value = "."
            };
            AppArgument     reset         = argList.Find(x => x.Name == "--reset");
            AppArgument     checkInstance = argList.Find(x => x.Name == "--processname");
            UpdaterSettings config        = CreateConfig();

            try
            {
                SetUpdateStatusAsync("Инициализация...");
                updater = new ConfigLoader(updatePath.Value, config);
                updater.ReadLocal();
                bool needExit = false;
                if (checkInstance != null)
                {
                    Process[] processes = Process.GetProcessesByName(checkInstance.Value);
                    if (processes.Length > 0)
                    {
                        HandleUpdateMessage("Это приложение уже запущено", checkInstance.Value, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        needExit = true;
                    }
                }
                if (!needExit)
                {
                    if (reset != null)
                    {
                        SetUpdateStatusAsync("Выполняется сброс информации об обновлениях...");
                        updater.ResetLocalConfig();
                        SetUpdateStatusAsync("Информация об обновлениях сброшена, завершение работы.");
                    }
                    else
                    {
                        SetUpdateStatusAsync("Загружаю файл с информацией об обновлениях...");
                        if (updater.GetLocal() == null)
                        {
                            updater.ResetLocalConfig();
                        }
                        Config localConfig  = updater.GetLocal();
                        Config remoteConfig = updater.GetRemote();

                        if (localConfig.Version < remoteConfig.Version)
                        {
                            SetUpdateStatusAsync("Обновление найдено, выполняется загрузка...");
                            string localUpdate = updater.DownloadUpdate(remoteConfig);
                            SetUpdateStatusAsync("Выполняется установка обновления...");
                            frm.DisableFormClosing = true;
                            if (ApplyUpdate(localUpdate, remoteConfig.Version))
                            {
                                SetUpdateStatusAsync("Обновление успешно установлено!");
                            }
                            else
                            {
                                SetUpdateStatusAsync("Не удалось установить обновление!");
                            }
                            frm.DisableFormClosing = false;
#if DEBUG
                            Thread.Sleep(3000);
#endif
                        }
                        else
                        {
                            SetUpdateStatusAsync("Oбновление не требуется!");
                        }
                        DoPostUpdateAction(updatePath.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                frm.DisableFormClosing = false;
                HandleUpdateExceptionAsync(ex);
                DoPostUpdateAction(updatePath.Value);
                return;
            }
            finally
            {
                frm.BeginInvoke(new WorkerFinish(UpdateCompleted));
            }
        }