Ejemplo n.º 1
0
        private UpdateManagerError DownloaFiles()
        {
            UpdateManagerError error        = UpdateManagerError.None;
            DirectoryInfo      downloadsDir = Configure.DownloadsDirectory;

            downloadsDir.Create();

            for (int i = _updateManager.CurrentVersionNumber + 1; i <= _updateManager.NewVersionNumber; i++)
            {
                string fileUserInfoPath = Configure.VersionUserInfoDirectoryName + "\\" + string.Format(Configure.VersionUserInfoFileName, i);

                FileInfo fileUserInfo = new FileInfo(Path.Combine(downloadsDir.FullName, fileUserInfoPath));

                string urlUserInfo = Configure.CreateScriptDownloadFile(fileUserInfoPath);
                error = _webReader.DownloadFileMethod(urlUserInfo, fileUserInfo);
                if (error != UpdateManagerError.None)
                {
                    return(error);
                }

                _userInfo.Add(string.Format(TEMPLATE_VERSION, i, File.ReadAllText(fileUserInfo.FullName)));
                _moveFiles.Add(new MoveFile(fileUserInfo, Configure.VersionUserInfoDirectory));
            }

            string filePath = Configure.UpdateFileListName;

            _updateFilesFile = new FileInfo(Path.Combine(downloadsDir.FullName, filePath));
            string url = Configure.CreateScriptDownloadFile(filePath);

            error = _webReader.DownloadFileMethod(url, _updateFilesFile);

            return(error);
        }
Ejemplo n.º 2
0
 public WebReaderEventArgs(FileInfo file, int size, UpdateManagerError error, string errorMessage)
 {
     _file         = file;
     _size         = size;
     _error        = error;
     _errorMessage = errorMessage;
 }
Ejemplo n.º 3
0
        public UpdateManagerError DownloadFileMethod(string url, FileInfo file)
        {
            string             errorMessage = "";
            UpdateManagerError error        = UpdateManagerError.None;
            int    size    = 0;
            string urlSize = url.Replace("?go=down", "?go=size");
            string page    = ReadPage(urlSize);

            OnStartDownloadFile(new WebReaderEventArgs(file, size, error, errorMessage));

            try {
                if (page == "")
                {
                    error = UpdateManagerError.ConnectionError;
                }
                else
                {
                    string[] sa = page.Split('\n');
                    if (sa.Length != 2 || sa[0] != "ok")
                    {
                        if (sa.Length >= 2)
                        {
                            errorMessage = sa[1];
                        }

                        error = UpdateManagerError.ServerError;
                    }
                    else
                    {
                        size = Convert.ToInt32(sa[1]);
                    }
                }
                if (error != UpdateManagerError.None)
                {
                    throw (new WebReaderException(error, errorMessage));
                }

                this.DownloadFile(url, file, size);
            } catch (WebReaderException we) {
                error        = we.Error;
                errorMessage = we.Message;
            } catch (Exception e) {
                error        = UpdateManagerError.Unknow;
                errorMessage = e.Message;
            } finally {
                OnStopDownloadFile(new WebReaderEventArgs(file, size, error, errorMessage));
            }
            return(error);
        }
Ejemplo n.º 4
0
 public void UpdateMethod()
 {
     _error = UpdateManagerError.None;
     this.OnStartUpdate(EventArgs.Empty);
     try {
         this.UpdateProcess();
     } catch (WebReaderException we) {
         _error        = we.Error;
         _errorMessage = we.Message;
     } catch (Exception e) {
         _error        = UpdateManagerError.Unknow;
         _errorMessage = e.Message;
     } finally {
         this.OnStopUpdate(EventArgs.Empty);
     }
 }
Ejemplo n.º 5
0
 public void GetUpdateDetailsMethod()
 {
     this.Load();
     _error = UpdateManagerError.None;
     this.OnStartGetUpdateDetails(EventArgs.Empty);
     try {
         this.GetUpdateDetailsProcess();
     } catch (WebReaderException we) {
         _error        = we.Error;
         _errorMessage = we.Message;
     } catch (Exception e) {
         _error        = UpdateManagerError.Unknow;
         _errorMessage = e.Message;
     } finally {
         this.OnStopGetUpdateDetails(EventArgs.Empty);
     }
 }
Ejemplo n.º 6
0
        public void CheckForUpdatesMethod()
        {
            this.Load();
            _error = UpdateManagerError.None;
            _checkForUpdateProcess = true;
            this.OnStartCheckForUpdates(EventArgs.Empty);
            try {
                if (!_isOldVersion)
                {
                    string url  = Configure.CreateScriptGetVersionUrl();
                    string page = WebReader.ReadPage(url);

                    if (page == "")
                    {
                        _error = UpdateManagerError.ConnectionError;
                    }
                    else
                    {
                        string[] sa = page.Split('\n');
                        if (sa.Length != 2 || sa[0] != "ok")
                        {
                            _error = UpdateManagerError.ServerError;
                        }
                        else
                        {
                            _newVersionNumber = Convert.ToInt32(sa[1]);

                            if (_newVersionNumber < 1)
                            {
                                _error = UpdateManagerError.ServerError;
                            }
                            else
                            {
                                if (_newVersionNumber > _currentVersionNumber)
                                {
                                    _isOldVersion = true;
                                }
                            }
                        }
                    }
                }
            } finally {
                _checkForUpdateProcess = false;
                this.OnStopCheckForUpdates(EventArgs.Empty);
            }
        }
Ejemplo n.º 7
0
        public static string ToString(UpdateManagerError error)
        {
            switch (error)
            {
            case UpdateManagerError.None:
                return("None");

            case UpdateManagerError.ConnectionError:
                return("Connection error");

            case UpdateManagerError.ServerError:
                return("Server error");

            case UpdateManagerError.Unknow:
                return("Unknow error");
            }
            return("Error");
        }
Ejemplo n.º 8
0
        private void CreateDetails()
        {
            DirectoryInfo dir = Configure.VersionUserInfoDirectory;

            for (int i = 1; i <= _updateManager.CurrentVersionNumber; i++)
            {
                string   templateVersion = i == _updateManager.CurrentVersionNumber ? TEMPLATE_VERSION_CURRENT : TEMPLATE_VERSION;
                string   userInfoHtml    = "";
                FileInfo userInfoFile    = new FileInfo(Path.Combine(Configure.VersionUserInfoDirectory.FullName, string.Format(Configure.VersionUserInfoFileName, i)));

                if (userInfoFile.Exists)
                {
                    userInfoHtml = File.ReadAllText(userInfoFile.FullName);
                }

                _userInfo.Add(string.Format(templateVersion, i, userInfoHtml));
            }

            WebReader          webReader = _updateManager.WebReader;
            UpdateManagerError error     = this.DownloaFiles();

            if (error != UpdateManagerError.None)
            {
                throw (new WebReaderException(error, ""));
            }

            _newUFI = new UpdateFileInfoManager(_updateFilesFile);
            _moveFiles.Add(new MoveFile(_updateFilesFile, Configure.UpdateDirectory));

            UpdateFileInfo[] ufis = this.GetUpdateFiles();
            int downloadSize      = 0;

            foreach (UpdateFileInfo ufi in ufis)
            {
                if (ufi.Action != UpdateFileInfoAction.Deleted)
                {
                    downloadSize += ufi.CompressSize;
                }
            }

            _userInfo.Add(string.Format(TEMPLATE_INFO_SIZE, ConvertToSize(downloadSize)));
        }
Ejemplo n.º 9
0
 public WebReaderException(UpdateManagerError error, string message)
     : base(message)
 {
     _error = error;
 }
Ejemplo n.º 10
0
        private void UpdateProcess()
        {
            this.GetUpdateDetailsProcess();
            UpdateFileInfo[] ufis = _udm.GetUpdateFiles();
            DirectoryInfo    dir  = new DirectoryInfo(Path.Combine(Configure.DownloadsDirectory.FullName, "files"));

            foreach (UpdateFileInfo ufi in ufis)
            {
                string   zipFile = ufi.FileInfo + ".zip";
                FileInfo file    = new FileInfo(Path.Combine(dir.FullName, zipFile));
                file.Directory.Create();

                string url = Configure.CreateScriptDownloadFile(zipFile);

                UpdateManagerError error = _webReader.DownloadFileMethod(url, file);

                if (error != UpdateManagerError.None)
                {
                    throw (new WebReaderException(error, ""));
                }
            }
            _isDownloadUpdateFiles = true;

            DirectoryInfo newReleaseDirectory = new DirectoryInfo(Path.Combine(Configure.UpdateDirectory.FullName, "newrelease"));

            try {
                if (newReleaseDirectory.Exists)
                {
                    newReleaseDirectory.Delete(true);
                }
            } catch { }
            newReleaseDirectory.Create();

            Exception exError = null;

            _abort = false;
            foreach (UpdateFileInfo ufi in ufis)
            {
                if (ufi.Action == UpdateFileInfoAction.Deleted)
                {
                    continue;
                }

                FileInfo zipFile  = new FileInfo(Path.Combine(dir.FullName, ufi.FileInfo + ".zip"));
                FileInfo destFile = new FileInfo(Path.Combine(newReleaseDirectory.FullName, ufi.FileInfo));

                this.OnStartUnZipFile(new UnZipFileEventArgs(zipFile));
                try {
                    this.UnZipFile(zipFile, destFile);
                } catch (Exception e) {
                    exError = e;
                }
                this.OnStopUnZipFile(new UnZipFileEventArgs(zipFile));
                if (exError != null)
                {
                    break;
                }
            }
            if (exError != null)
            {
                throw (exError);
            }


            DirectoryInfo prevRelDir = Configure.PrevReleaseDirectory;

            try{
                if (prevRelDir.Exists)
                {
                    prevRelDir.Delete(true);
                }
            }catch {}

            /* Move old file */
            foreach (UpdateFileInfo ufi in ufis)
            {
                FileInfo sourceFile = new FileInfo(LURootFolder.Convert(ufi.FileInfo));
                FileInfo destFile   = new FileInfo(Path.Combine(prevRelDir.FullName, ufi.FileInfo));

                if (ufi.Action == UpdateFileInfoAction.Deleted)
                {
                    destFile = new FileInfo(destFile.FullName + ".upddeleted");
                }

                destFile.Directory.Create();

                File.Move(sourceFile.FullName, destFile.FullName);
            }

            /* Move new File*/
            foreach (UpdateFileInfo ufi in ufis)
            {
                if (ufi.Action == UpdateFileInfoAction.Deleted)
                {
                    return;
                }

                FileInfo sourceFile = new FileInfo(Path.Combine(newReleaseDirectory.FullName, ufi.FileInfo));
                FileInfo destFile   = new FileInfo(LURootFolder.Convert(ufi.FileInfo));
                File.Move(sourceFile.FullName, destFile.FullName);
            }

            try {
                newReleaseDirectory.Delete(true);
            } catch { }

            _udm.UpdateComplete();

            FileInfo fileVersionNumber = new FileInfo(Path.Combine(Configure.UpdateDirectory.FullName, Configure.VersionNumberFileName));

            if (fileVersionNumber.Exists)
            {
                fileVersionNumber.Delete();
            }
            File.WriteAllText(fileVersionNumber.FullName, _newVersionNumber.ToString());

            try {
                Configure.DownloadsDirectory.Delete(true);
            } catch { }

            _isUpdateComplete = true;
        }