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);
        }
Beispiel #2
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;
        }