Ejemplo n.º 1
0
 protected internal UpdateArgs(UpdateState updateState, UpdateFileInfo updateFileInfo, int filesCount, int currentIndex, DownloadInfo downloadInfo = null)
 {
     UpdateState    = updateState;
     UpdateFileInfo = updateFileInfo;
     FilesCount     = filesCount;
     CurrentIndex   = currentIndex;
     DownloadInfo   = downloadInfo;
 }
Ejemplo n.º 2
0
        internal static bool CheckFileIsUpdate(UpdateFileInfo updateFileInfo)
        {
            bool result = false;
            //Console.WriteLine($"文件名:{updateFileInfo.FileName},路径:{updateFileInfo.FilePath},版本:{updateFileInfo.FileVersion},大小:{updateFileInfo.FileSize},MD5:{updateFileInfo.MD5HashStr},检测方式:{updateFileInfo.VerificationType}");
            string fileName = updateFileInfo.FilePath;

            if (fileName.StartsWith(@"\"))
            {
                fileName = fileName.Trim('\\');
            }
            string checkFile = Path.Combine(Environment.CurrentDirectory, fileName);

            if (File.Exists(checkFile))
            {
                if (updateFileInfo.VerificationType == VerificationType.Version)
                {
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(checkFile);
                    WriteLog_Information("检查文件更新,检测方式:{0},文件:{1},服务器版本:{2},本地版本:{3}", updateFileInfo.VerificationType, checkFile, updateFileInfo.FileVersion, fileVersionInfo.FileVersion);
                    if (fileVersionInfo.FileVersion != updateFileInfo.FileVersion)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    string md5Hash = MD5Hash.GetMD5HashFromFile(checkFile);
                    WriteLog_Information("检查文件更新,检测方式:{0},文件:{1},服务器MD5Hash:{2},本地MD5Hash:{3}", updateFileInfo.VerificationType, checkFile, updateFileInfo.MD5HashStr, md5Hash);
                    if (md5Hash != updateFileInfo.MD5HashStr)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            else
            {
                WriteLog_Information("检查文件更新,文件:{0} 本地文件不存在", checkFile);
                result = true;
            }
            if (result)
            {
                WriteLog_Information("\t\t文件:{0} 信息与服务器不一致,需要更新", checkFile);
            }
            else
            {
                WriteLog_Information("\t\t文件:{0} 信息与服务器一致,不需要更新", checkFile);
            }
            return(result);
        }
Ejemplo n.º 3
0
 private void Button4_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex >= 0)
     {
         UpdateFileInfo fileInfo = comboBox1.SelectedItem as UpdateFileInfo;
         if (richTextBox1.SelectionLength > 0)
         {
             richTextBox1.SelectionStart = richTextBox1.SelectionStart + richTextBox1.SelectionLength;
         }
         richTextBox1.SelectedText = $"文件名:{fileInfo.FileName},文件版本:{fileInfo.FileVersion}";
     }
 }
Ejemplo n.º 4
0
        public async Task <bool> DownloadFile(UpdateFileInfo file, ProgressBar pBar, string destFileName)
        {
            var fullPath = Path.Combine(_settings.LocalUltimaPath, destFileName);
            var uri      = file.Uri;

            using (var response = _httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result)
            {
                response.EnsureSuccessStatusCode();

                using (Stream contentStream = await response.Content.ReadAsStreamAsync(), fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
                {
                    var totalRead    = 0L;
                    var totalReads   = 0L;
                    var buffer       = new byte[8192];
                    var isMoreToRead = true;
                    var percentage   = 0;

                    do
                    {
                        var read = await contentStream.ReadAsync(buffer, 0, buffer.Length);

                        if (read == 0)
                        {
                            isMoreToRead = false;
                        }
                        else
                        {
                            await fileStream.WriteAsync(buffer, 0, read);

                            totalRead  += read;
                            totalReads += 1;

                            var percentageTotal =
                                (int)Math.Round(
                                    ((decimal)totalRead / (file.SizeInKb * 10)), 0);


                            if (percentageTotal > percentage)
                            {
                                pBar.Tick();
                                percentage = percentageTotal;
                            }
                        }
                    }while (isMoreToRead);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Projects the UpdateFileInfo into a <see cref="FileCacheEntry"/>
        /// </summary>
        /// <param name="file">The <see cref="UpdateFileInfo"/> received from remote</param>
        /// <param name="fileName">Filename stored on local FS</param>
        /// <returns>true when added</returns>
        public bool AddFile(UpdateFileInfo file, string fileName)
        {
            if (SavedFiles == null)
            {
                SavedFiles = new List <FileCacheEntry>();
            }


            SavedFiles.Add(new FileCacheEntry()
            {
                FileName = fileName,
                Name     = file.Name,
                Revision = file.Revision
            });

            return(true);
        }
Ejemplo n.º 6
0
    //获取差异文件
    public ArrayList getDiffFiles(PatchInfo other)
    {
        ArrayList list = new ArrayList();

        foreach (KeyValuePair <string, UpdateFileInfo> info in other.fileList)
        {
            string         key     = info.Key;
            UpdateFileInfo newInfo = info.Value;
            UpdateFileInfo curInfo = null;
            fileList.TryGetValue(key, out curInfo);
            if (curInfo != null && curInfo.equal(newInfo))
            {
                continue;
            }
            list.Add(key);
        }
        return(list);
    }
Ejemplo n.º 7
0
 private bool CheckFileMd5(UpdateFileInfo file)
 {
     using (var md5 = MD5.Create())
     {
         using (var stream = File.OpenRead(".\\" + file.LocalFilePath))
         {
             string filehash = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
             if (filehash == file.FileMD5Hash)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
 }
Ejemplo n.º 8
0
 private void Button2_Click(object sender, EventArgs e)
 {
     using (SaveFileDialog saveFileDialog = new SaveFileDialog())
     {
         saveFileDialog.FileName         = "update.json";
         saveFileDialog.CheckPathExists  = true;
         saveFileDialog.RestoreDirectory = true;
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             Console.WriteLine(saveFileDialog.FileName);
             List <VersionInfo> versionInfos;
             if (oldUpdateInfo != null)
             {
                 versionInfos = new List <VersionInfo>(oldUpdateInfo.VersionInfos);
             }
             else
             {
                 versionInfos = new List <VersionInfo>();
             }
             List <UpdateFileInfo> fileInfos = new List <UpdateFileInfo>(newUpdateInfo.FileInfos);
             UpdateFileInfo        fileInfo  = fileInfos.Find(f => f.FileName == Form_UpdateConfig.MainExe);
             if (fileInfo == null)
             {
                 MessageBox.Show($"未包含主程序 {Form_UpdateConfig.MainExe}");
                 return;
             }
             versionInfos.Add(new VersionInfo()
             {
                 Index          = versionInfos.Count + 1,
                 Version        = fileInfo.FileVersion,
                 UpdateDescribe = richTextBox1.Text.Replace("\n", "\r\n"),
                 UpdateDate     = DateTime.Now.ToString("yyyy-MM-dd HH:mm")
             });
             VersionInfo[] vis = versionInfos.ToArray();
             Array.Sort(vis);
             newUpdateInfo.VersionInfos = vis;
             string json = Json.JsonSerialize(newUpdateInfo);
             Console.WriteLine(json);
             File.WriteAllText(saveFileDialog.FileName, json);
         }
     }
 }
Ejemplo n.º 9
0
        private bool UpdateFileProcess(UpdateFileInfo _nuFile, string stUpdateName)
        {
            //改显示信息
            RaiseUpdateProgress(string.Format("正在下载{0}文件{1}版本...", _nuFile.FileName, _nuFile.AvailableVersion));
            //下载
            DirectoryInfo diDest = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
            string        stPath = diDest.Parent.FullName + System.IO.Path.DirectorySeparatorChar + _nuFile.FileName + ".zip";

            if (this.downloadFile(_nuFile.AppFileURL, stPath))
            {
                //XtraMessageBox.Show("Downloaded New File");
                string stDest = diDest.Parent.FullName + System.IO.Path.DirectorySeparatorChar + stUpdateName + System.IO.Path.DirectorySeparatorChar;
                if (!Directory.Exists(stDest))
                {
                    Directory.CreateDirectory(stDest);
                }
                stDest += _nuFile.FileName;
                //Extract Zip File
                try
                {
                    //this.unzip(stPath, stDest);
                    DecompressFile(stPath, stDest);
                }
                catch (Exception e)
                {
                    RaiseUpdateError(string.Format("解压升级文件{0}失败!\n自动更新过程失败!\n {1}", _nuFile.AppFileURL, e.Message));
                    return(false);
                }

                //Delete Zip File
                File.Delete(stPath);
                //Restart App if Necessary
                //If true, the app will restart automatically, if false the app will use the RestartForm to prompt the user, if RestartForm is null, it doesn't restart
                //else don't restart
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Проверка наличия обновлений
        /// </summary>
        /// <returns>bool, UpdateFileInfo. Если true то UpdateFileInfo заполнен из файла обновления</returns>
        public static (bool, UpdateFileInfo) IsEnableUpdate()
        {
            SetLauncherContext sContext = new SetLauncherContext();
            var            result       = false;
            UpdateFileInfo ufInfo       = new UpdateFileInfo();

            if (Directory.Exists(sContext.Settings.PathToUpdate))
            {
                var filePath = sContext.Settings.PathToUpdate + sContext.Settings.FileInfo;
                if (File.Exists(filePath))
                {
                    var json = File.ReadAllText(filePath);
                    ufInfo = JsonConvert.DeserializeObject <UpdateFileInfo>(json);
                    if (ufInfo.Build > sContext.Settings.Build)
                    {
                        result = true;
                    }
                }
            }
            return(result, ufInfo);
        }
Ejemplo n.º 11
0
        private void GridFiles_DragDrop(object sender, DragEventArgs e)
        {
            var filterList = AppContext.FilterList.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            var filePaths  = e.Data.GetData(DataFormats.FileDrop) as string[];

            if (filePaths != null && filePaths.Length > 0)
            {
                var updateFiles = bindingSource.DataSource as List <UpdateFileInfo>;
                foreach (var item in filePaths)
                {
                    if (filterList.Any(x => item.Contains(x)))
                    {
                        continue;
                    }

                    if (!File.Exists(item))
                    {
                        continue;
                    }

                    if (updateFiles.Exists(x => x.FilePath == item))
                    {
                        continue;
                    }

                    if (!item.StartsWith(this.Config.ClientRootPath))
                    {
                        UpdateLog($"文件 {item}不在客户端根目录下,无法添加");
                        continue;
                    }

                    var fileInfo = new UpdateFileInfo();
                    fileInfo.FilePath     = item;
                    fileInfo.RelativePath = item.Replace(this.Config.ClientRootPath, "").TrimStart('\\');

                    bindingSource.Add(fileInfo);
                }
            }
        }
Ejemplo n.º 12
0
    //从文本文件读取信息
    public void loadContent(string path)
    {
        fileList.Clear();
        string ret = null;

        path += "/files.txt";
        try
        {
            ret = File.ReadAllText(path);
            string[] fileContent = ret.Split(new string[] { "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < fileContent.Length; i++)
            {
                UpdateFileInfo fileInfo = new UpdateFileInfo(fileContent[i]);
                fileList[fileInfo.filePath] = fileInfo;
            }
            isVaild = true;
        }
        catch
        {
            Debug.Log(" 没有找到文件 files.txt");
        }
        storePath = Path.GetDirectoryName(path);
    }
Ejemplo n.º 13
0
 private void CheckNextFile()
 {
     try
     {
         _currentServerFile++;
         if (_currentServerFile == _serverFiles.Count())
         {
             OpenVPMobile();
             return;
         }
         if (_serverFiles != null || _serverFiles.Count() > 0)
         {
             UpdateFileInfo f = _serverFiles[_currentServerFile];
             CurrentFile = "Checking file:  " + Path.GetFileName(f.FileName);
             string filePath = Path.Combine(CurrentMobileDirectory, f.RelativeFilePath);
             if (!Directory.Exists(Path.GetDirectoryName(filePath)))
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(filePath));
             }
             if (!File.Exists(filePath) || File.GetLastWriteTimeUtc(filePath).CompareTo(f.FileDate) < 0)
             {
                 Logging.LogMessage(Logging.LogType.Info, f.FileName + " - Local: " + File.GetLastWriteTimeUtc(filePath).ToString("MM/dd hh:mm:ss.ffff") + " || Server: " + f.FileDate.ToString("MM/dd hh:mm:ss.ffff"));
                 CurrentFile = "Updating file:  " + Path.GetFileName(f.FileName);
                 MobileService.GetMainUpdateFileAsync(f.RelativeFilePath, filePath);
             }
             else
             {
                 CheckNextFile();
             }
         }
     }
     catch (Exception ex)
     {
         var message = "Error checking file";
         Logging.LogMessage(Logging.LogType.Error, message, ex);
     }
 }
Ejemplo n.º 14
0
 private void GenerateUpdateInfoFile()
 {
     try {
         string[] filesPaths = Directory.GetFiles(FolderPathOut + "Upadate\\", "*", SearchOption.AllDirectories);
         List <UpdateFileInfo> updateFileInfo = new List <UpdateFileInfo>();
         for (int i = 0; i < filesPaths.Length; i++)
         {
             string         HASH     = GetMD5HashFromFile(filesPaths[i]);
             UpdateFileInfo fileInfo = new UpdateFileInfo();
             fileInfo.FileMD5Hash   = HASH;
             fileInfo.LocalFilePath = filesPaths[i].Substring((FolderPathOut + "Upadate\\").Length);
             updateFileInfo.Add(fileInfo);
             RasePatchGenerateProgressEvent(new PatchMakerGeneratingEventArgs()
             {
                 countFiles  = filesPaths.Length,
                 currentDone = i
             });
         }
         string outFile = JsonConvert.SerializeObject(updateFileInfo, Formatting.Indented);
         File.WriteAllText(FolderPathOut + "updateInfo.json", outFile);
     } catch (Exception e) {
         MessageBox.Show($"Error:{e.ToString()}");
     }
 }
Ejemplo n.º 15
0
        void CheckUpdateDoWork(object sender, DoWorkEventArgs e)
        {
            const string serverPath      = "http://www.jt-soft.de/videoconvert/";
            const string serverPathTools = "http://www.jt-soft.de/videoconvert/tools/";
            string       tempPath        = AppSettings.TempPath;

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                WebClient downloader = new WebClient {
                    UseDefaultCredentials = true
                };
                Stream onlineUpdateFile;
                try
                {
                    onlineUpdateFile = downloader.OpenRead(new Uri("http://www.jt-soft.de/videoconvert/updatefile_7z.xml"));
                }
                catch (WebException exception)
                {
                    Log.Error(exception);
                    e.Result = false;
                    return;
                }

                if (onlineUpdateFile == null)
                {
                    e.Result = false;
                    return;
                }

                using (UpdateFileInfo updateFile = Updater.LoadUpdateFileFromStream(onlineUpdateFile))
                {
                    if (updateFile.Core.PackageVersion.CompareTo(AppSettings.GetAppVersion()) > 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "Core",
                            LocalVersion  = AppSettings.GetAppVersion().ToString(4),
                            ServerVersion = updateFile.Core.PackageVersionStr,
                            FileName      =
                                Path.Combine(tempPath, updateFile.Core.PackageName),
                            DownloadUri  = serverPath + updateFile.Core.PackageName,
                            DownloadType = AppType.MainApp,
                            Destination  = AppSettings.AppPath
                        });
                    }

                    if (updateFile.Updater.PackageVersion.CompareTo(AppSettings.UpdaterVersion) > 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "Updater (UAC Compatible)",
                            LocalVersion  = AppSettings.UpdaterVersion.ToString(4),
                            ServerVersion = updateFile.Updater.PackageVersionStr,
                            FileName      =
                                Path.Combine(tempPath, updateFile.Updater.PackageName),
                            DownloadUri  = serverPath + updateFile.Updater.PackageName,
                            DownloadType = AppType.Updater,
                            Destination  = AppSettings.UpdaterPath
                        });
                    }

                    if (
                        String.CompareOrdinal(updateFile.AviSynthPlugins.PackageVersion,
                                              AppSettings.LastAviSynthPluginsVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "AviSynth Plugins",
                            LocalVersion  = AppSettings.LastAviSynthPluginsVer,
                            ServerVersion = updateFile.AviSynthPlugins.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.AviSynthPlugins.PackageName),
                            DownloadUri   = serverPath + updateFile.AviSynthPlugins.PackageName,
                            DownloadType  = AppType.AviSynthPlugins,
                            Destination   = AppSettings.AvsPluginsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.Profiles.PackageVersion, AppSettings.LastProfilesVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "Profiles",
                            LocalVersion  = AppSettings.LastProfilesVer,
                            ServerVersion = updateFile.Profiles.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.Profiles.PackageName),
                            DownloadUri   = serverPath + updateFile.Profiles.PackageName,
                            DownloadType  = AppType.Profiles,
                            Destination   = AppSettings.CommonAppSettingsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.X264.PackageVersion, AppSettings.Lastx264Ver) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "x264",
                            LocalVersion  = AppSettings.Lastx264Ver,
                            ServerVersion = updateFile.X264.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.X264.PackageName),
                            DownloadUri   = serverPathTools + updateFile.X264.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.X26464.PackageVersion, AppSettings.Lastx26464Ver) != 0 &&
                        Environment.Is64BitOperatingSystem)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "x264 (64 bit)",
                            LocalVersion  = AppSettings.Lastx26464Ver,
                            ServerVersion = updateFile.X26464.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.X26464.PackageName),
                            DownloadUri   = serverPathTools + updateFile.X26464.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.FFMPEG.PackageVersion, AppSettings.LastffmpegVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "ffmpeg",
                            LocalVersion  = AppSettings.LastffmpegVer,
                            ServerVersion = updateFile.FFMPEG.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.FFMPEG.PackageName),
                            DownloadUri   = serverPathTools + updateFile.FFMPEG.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.FFMPEG64.PackageVersion, AppSettings.Lastffmpeg64Ver) != 0 &&
                        Environment.Is64BitOperatingSystem)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "ffmpeg (64 bit)",
                            LocalVersion  = AppSettings.Lastffmpeg64Ver,
                            ServerVersion = updateFile.FFMPEG64.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.FFMPEG64.PackageName),
                            DownloadUri   = serverPathTools + updateFile.FFMPEG64.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.Eac3To.PackageVersion, AppSettings.Lasteac3ToVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "eac3to",
                            LocalVersion  = AppSettings.Lasteac3ToVer,
                            ServerVersion = updateFile.Eac3To.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.Eac3To.PackageName),
                            DownloadUri   = serverPathTools + updateFile.Eac3To.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.LsDvd.PackageVersion, AppSettings.LastlsdvdVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "lsdvd",
                            LocalVersion  = AppSettings.LastlsdvdVer,
                            ServerVersion = updateFile.LsDvd.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.LsDvd.PackageName),
                            DownloadUri   = serverPathTools + updateFile.LsDvd.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.MKVToolnix.PackageVersion, AppSettings.LastMKVMergeVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "MKVToolnix",
                            LocalVersion  = AppSettings.LastMKVMergeVer,
                            ServerVersion = updateFile.MKVToolnix.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.MKVToolnix.PackageName),
                            DownloadUri   = serverPathTools + updateFile.MKVToolnix.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.Mplayer.PackageVersion, AppSettings.LastMplayerVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "MPlayer",
                            LocalVersion  = AppSettings.LastMplayerVer,
                            ServerVersion = updateFile.Mplayer.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.Mplayer.PackageName),
                            DownloadUri   = serverPathTools + updateFile.Mplayer.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.TSMuxeR.PackageVersion, AppSettings.LastTSMuxerVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "TSMuxeR",
                            LocalVersion  = AppSettings.LastTSMuxerVer,
                            ServerVersion = updateFile.TSMuxeR.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.TSMuxeR.PackageName),
                            DownloadUri   = serverPathTools + updateFile.TSMuxeR.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.MjpegTools.PackageVersion, AppSettings.LastMJPEGToolsVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "mjpegtools",
                            LocalVersion  = AppSettings.LastMJPEGToolsVer,
                            ServerVersion = updateFile.MjpegTools.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.MjpegTools.PackageName),
                            DownloadUri   = serverPathTools + updateFile.MjpegTools.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.DVDAuthor.PackageVersion, AppSettings.LastDVDAuthorVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "DVDAuthor",
                            LocalVersion  = AppSettings.LastDVDAuthorVer,
                            ServerVersion = updateFile.DVDAuthor.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.DVDAuthor.PackageName),
                            DownloadUri   = serverPathTools + updateFile.DVDAuthor.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.MP4Box.PackageVersion, AppSettings.LastMp4BoxVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "MP4Box",
                            LocalVersion  = AppSettings.LastMp4BoxVer,
                            ServerVersion = updateFile.MP4Box.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.MP4Box.PackageName),
                            DownloadUri   = serverPathTools + updateFile.MP4Box.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.HcEnc.PackageVersion, AppSettings.LastHcEncVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "HCEnc",
                            LocalVersion  = AppSettings.LastHcEncVer,
                            ServerVersion = updateFile.HcEnc.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.HcEnc.PackageName),
                            DownloadUri   = serverPathTools + updateFile.HcEnc.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.OggEnc.PackageVersion, AppSettings.LastOggEncVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "OggEnc2",
                            LocalVersion  = AppSettings.LastOggEncVer,
                            ServerVersion = updateFile.OggEnc.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.OggEnc.PackageName),
                            DownloadUri   = serverPathTools + updateFile.OggEnc.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.OggEncLancer.PackageVersion, AppSettings.LastOggEncLancerVer) != 0 &&
                        AppSettings.UseOptimizedEncoders)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "OggEnc2 (Lancer)",
                            LocalVersion  = AppSettings.LastOggEncLancerVer,
                            ServerVersion = updateFile.OggEncLancer.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.OggEncLancer.PackageName),
                            DownloadUri   = serverPathTools + updateFile.OggEncLancer.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.Lame.PackageVersion, AppSettings.LastLameVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "Lame",
                            LocalVersion  = AppSettings.LastLameVer,
                            ServerVersion = updateFile.Lame.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.Lame.PackageName),
                            DownloadUri   = serverPathTools + updateFile.Lame.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.VpxEnc.PackageVersion, AppSettings.LastVpxEncVer) != 0)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "VP8 Encoder",
                            LocalVersion  = AppSettings.LastVpxEncVer,
                            ServerVersion = updateFile.VpxEnc.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.VpxEnc.PackageName),
                            DownloadUri   = serverPathTools + updateFile.VpxEnc.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }

                    if (String.CompareOrdinal(updateFile.BDSup2Sub.PackageVersion, AppSettings.LastBDSup2SubVer) != 0 &&
                        AppSettings.JavaInstalled)
                    {
                        _tempToolCollection.Add(new ToolVersions
                        {
                            ToolName      = "bdsup2sub",
                            LocalVersion  = AppSettings.LastBDSup2SubVer,
                            ServerVersion = updateFile.BDSup2Sub.PackageVersion,
                            FileName      = Path.Combine(tempPath, updateFile.BDSup2Sub.PackageName),
                            DownloadUri   = serverPathTools + updateFile.BDSup2Sub.PackageName,
                            DownloadType  = AppType.Encoder,
                            Destination   = AppSettings.ToolsPath
                        });
                    }
                }
            }

            e.Result = true;
        }
Ejemplo n.º 16
0
        public bool DownLoad()
        {
            if (Tool.Int(Tool.GetUpdateXmlValue("isStartUsing")) != 1)
            {
                // 不启用返回true
                return(true);
            }

            bool blnRet = false;
            //文件路径
            string strCurrDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //Directory.GetCurrentDirectory();
            string strTempDir = strCurrDir + "\\Temp_Update";
            //WCF代理
            ProxyUpdate proxy = new ProxyUpdate();

            try
            {
                frmInit frmStart = new frmInit();
                frmStart.Show();
                Application.DoEvents();

                #region 比较版本号
                decimal decLocalVersion = 0;
                string  strLocalVersion = Tool.GetUpdateXmlValue("version");
                decimal.TryParse(strLocalVersion.Replace(".", ""), out decLocalVersion);

                decimal decSvcVersion = 0;
                string  strSvcVersion = string.Empty;

                proxy.Service.GetVersion(ref strSvcVersion);
                decimal.TryParse(strSvcVersion.Replace(".", ""), out decSvcVersion);

                bool blnAllDown = false;
                int  intDiff    = (int)(decSvcVersion - decLocalVersion);

                if (intDiff <= 0)
                {
                    frmStart.Dispose();
                    frmStart = null;
                    return(true);
                }
                if (intDiff == 1)
                {
                    blnAllDown = false;
                }
                else
                {
                    blnAllDown = true;
                }
                #endregion

                #region 更新列表
                List <string> lstFile = proxy.Service.GetUpdateFileList(blnAllDown);
                if (lstFile == null || lstFile.Count == 0)
                {
                    frmStart.Dispose();
                    frmStart = null;
                    return(true);
                }

                int                   intPos      = 0;
                int                   intTotal    = lstFile.Count();
                UpdateFileInfo        objFileInfo = null;
                List <UpdateFileInfo> lstFileInfo = new List <UpdateFileInfo>();
                foreach (string str in lstFile)
                {
                    objFileInfo = new UpdateFileInfo();

                    intPos = str.LastIndexOf("\\");
                    if (intPos >= 0)
                    {
                        objFileInfo.SubDirectory = str.Substring(0, intPos);
                        objFileInfo.FileName     = str.Substring(intPos + 1);
                    }
                    else
                    {
                        objFileInfo.SubDirectory = string.Empty;
                        objFileInfo.FileName     = str;
                    }
                    lstFileInfo.Add(objFileInfo);
                }

                frmStart.Dispose();
                frmStart = null;

                frmUpdate frm = new frmUpdate();
                frm.progressBarControl.Properties.Maximum = intTotal;
                frm.lblFile.Text = "准备下载文件...";
                frm.Show();
                Application.DoEvents();

                try
                {
                    if (Directory.Exists(strTempDir))
                    {
                        Directory.Delete(strTempDir, true);
                    }
                    Directory.CreateDirectory(strTempDir);

                    byte[]     bytFile    = null;
                    FileStream fileStream = null;
                    for (int i = 0; i < lstFileInfo.Count; i++)
                    {
                        objFileInfo      = lstFileInfo[i];
                        frm.lblFile.Text = "更新进度(" + Convert.ToString(i + 1) + "/" + intTotal.ToString() + ") : " + objFileInfo.FileName;
                        Application.DoEvents();

                        if (objFileInfo.SubDirectory != string.Empty)
                        {
                            if (!Directory.Exists(strTempDir + "\\" + objFileInfo.SubDirectory))
                            {
                                Directory.CreateDirectory(strTempDir + "\\" + objFileInfo.SubDirectory);
                            }
                        }
                        try
                        {
                            bytFile = proxy.Service.DownLoadFile(objFileInfo.SubDirectory + "\\" + objFileInfo.FileName);
                            if (bytFile != null)
                            {
                                objFileInfo.FileValue    = bytFile;
                                objFileInfo.TempFilePath = strTempDir + "\\" + objFileInfo.SubDirectory + "\\" + objFileInfo.FileName;
                                objFileInfo.WorkFilePath = strCurrDir + "\\" + objFileInfo.SubDirectory + "\\" + objFileInfo.FileName;
                                fileStream = new FileStream(objFileInfo.TempFilePath, FileMode.CreateNew);
                                fileStream.Write(bytFile, 0, bytFile.Length);
                                fileStream.Close();
                                fileStream.Dispose();
                                fileStream = null;
                            }
                            else
                            {
                                MessageBox.Show("下载文件: " + objFileInfo.FileName + " 失败。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("下载文件: " + objFileInfo.FileName + " 失败。\r\n\r\n" + e.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }

                        frm.progressBarControl.EditValue = i + 1;
                        Application.DoEvents();
                    }

                    #region 更新本地文件
                    frm.lblFile.Text = "下载完毕,更新本地文件请稍候...";
                    Application.DoEvents();

                    foreach (UpdateFileInfo objFile in lstFileInfo)
                    {
                        if (objFile.SubDirectory != string.Empty)
                        {
                            if (!Directory.Exists(strCurrDir + "\\" + objFile.SubDirectory))
                            {
                                Directory.CreateDirectory(strCurrDir + "\\" + objFile.SubDirectory);
                            }
                        }
                        if (File.Exists(objFile.WorkFilePath))
                        {
                            if (blnAllDown)
                            {
                                if (VerifyMd5Hash(GetMd5Hash(GetFile(objFile.WorkFilePath)), GetMd5Hash(objFile.FileValue)))
                                {
                                    continue;
                                }
                            }

                            File.SetAttributes(objFile.WorkFilePath, FileAttributes.Normal);
                            File.Delete(objFile.WorkFilePath);
                        }
                        File.Move(objFile.TempFilePath, objFile.WorkFilePath);
                    }
                    // 更新本地版本号
                    UpdateVersion(strSvcVersion);
                    #endregion

                    #region 注册文件 Ver:1.0
                    if (decLocalVersion == 10)
                    {
                        string strBatFile = Application.StartupPath + "\\RegOcx.bat";
                        if (File.Exists(strBatFile))
                        {
                            frm.lblFile.Text = "注册控件,请稍候...";
                            Application.DoEvents();

                            Process p = new Process();
                            p.StartInfo.FileName = strBatFile;
                            p.Start();
                            if (p.HasExited)
                            {
                                p.Kill();
                            }
                        }
                    }
                    #endregion

                    #region 释放
                    frm.Hide();
                    frm.Dispose();
                    frm = null;
                    Application.DoEvents();
                    #endregion

                    blnRet = true;
                }
                catch (Exception objEx)
                {
                    MessageBox.Show(objEx.Message);
                    frm.Hide();
                    frm.Dispose();
                    frm = null;
                    return(false);
                }
                #endregion
            }
            finally
            {
                proxy = null;
                if (Directory.Exists(strTempDir))
                {
                    Directory.Delete(strTempDir, true);
                }
            }
            return(blnRet);
        }
Ejemplo n.º 17
0
    //添加文件信息
    public void addFileInfo(string content)
    {
        UpdateFileInfo info = new UpdateFileInfo(content);

        fileList[info.filePath] = info;
    }
Ejemplo n.º 18
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //取源目录文件列表
            string SourcePath       = this.be_SourceDir.EditValue.ToString();
            string DownloadUrl      = this.te_URL.EditValue.ToString();
            string TargetPath       = this.be_TargetDir.EditValue.ToString() + "\\";
            string SourceConfigFile = this.buttonEdit1.EditValue.ToString();


            if (SourcePath == "" || DownloadUrl == "" || TargetPath == "" || SourceConfigFile == "")
            {
                MessageBox.Show("请录入生成目录、源升级文件目录、源配置文件、下级网站地址等内容!");
                return;
            }

            AssemblyName myAssemblyName = null;

            #region 生成DLL配置文件列表
            //配置文件
            AutoUpdateConfig _configFile = new AutoUpdateConfig();
            _configFile.CurrentVersionfiles = new List <UpdateFileInfo>();


            DirectoryInfo dirInfo = new DirectoryInfo(SourcePath);
            foreach (FileSystemInfo _fs in dirInfo.GetFileSystemInfos())
            {
                string FileName = "";
                string FileExt  = "";
                //如果是文件
                if (_fs is FileInfo)
                {
                    FileInfo fi = (FileInfo)_fs;
                    FileName = fi.Name;
                    //取得文件的扩展名
                    FileExt = fi.Extension.ToUpper();

                    if (FileExt == ".DLL" || FileExt == ".EXE")
                    {
                        string _packFileName = FileName + ".zip";
                        myAssemblyName = AssemblyName.GetAssemblyName(_fs.FullName);
                        //比较版本号,如果有新版本,加入下载更新列表
                        string _downloadFileName = DownloadUrl + _packFileName;
                        string TargetFileName    = TargetPath + _packFileName;
                        ZipFile(_fs.FullName, TargetFileName);

                        UpdateFileInfo _ufi = new UpdateFileInfo(fi.Name, myAssemblyName.Version.ToString(), _downloadFileName);
                        _configFile.CurrentVersionfiles.Add(_ufi);

                        this.te_Out.EditValue = (string)this.te_Out.EditValue + "\r\n" +
                                                string.Format(" {0},{1},{2} ", _ufi.FileName, _ufi.AvailableVersion, _ufi.AppFileURL);
                        Application.DoEvents();
                    }
                }
            }

            //生成配置文件
            string _ConfigFileName = TargetPath + "UpdateVersion.xml";

            if (File.Exists(_ConfigFileName))
            {
                File.Delete(_ConfigFileName);
            }
            StreamWriter _fw = File.CreateText(_ConfigFileName);
            _fw.WriteLine(@"<VersionConfig>");
            foreach (UpdateFileInfo _ufi in _configFile.CurrentVersionfiles)
            {
                _fw.WriteLine(string.Format("<FileName Name=\"{0}\" Version=\"{1}\" AppFileURL=\"{2}\"/>",
                                            _ufi.FileName, _ufi.AvailableVersion, _ufi.AppFileURL));
            }
            _fw.WriteLine(@"</VersionConfig>");

            _fw.Close();

            #endregion

            #region 生成客户端配置更新文件
            string _pluginFileName = TargetPath + "UpdateApp.xml";
            File.Copy(SourceConfigFile, _pluginFileName, true);


            #endregion

            MessageBox.Show("自动更新升级包制作完成!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 19
0
        private void button1_Click(object sender, EventArgs e)
        {
            // check files we need to update
            _updateFile = new UpdateFile();

            _updateFile.Message = textBox1.Text;
            _updateFile.Version = Assembly.LoadFile(Settings.Default.BaseFile).GetName().Version.ToString();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                var f = new UpdateFileInfo();

                f.SystemPath  = row.Cells[0].Value.ToString();
                f.Md5Hash     = row.Cells[1].Value.ToString();
                f.DownloadUri = "http://update.utopiarealms.com/files/" + f.SystemPath.Replace('\\', '/');

                var fi = new FileInfo(Path.Combine(_baseFolderPath, f.SystemPath));
                f.Length        = fi.Length;
                f.LastWriteTime = fi.LastWriteTimeUtc;

                _updateFile.Files.Add(f);
            }

            var ms     = new MemoryStream();
            var writer = new BinaryWriter(ms);

            foreach (var fileInfo in _updateFile.Files)
            {
                fileInfo.Save(writer);
            }
            ms.Position = 0;
            var hash = Md5Hash.Calculate(ms);

            _updateFile.UpdateToken = hash.ToString();

            if (_previousFile != null)
            {
                _newFiles = _updateFile.GetChangedFiles(_previousFile);
            }
            else
            {
                _newFiles = _updateFile.Files;
            }

            if (_newFiles.Count == 0)
            {
                MessageBox.Show("No changes found.");
                return;
            }


            // upload them
            _finished = false;
            var progressForm = new FrmProgress();

            progressForm.Progress = _progress;
            progressForm.Label    = _file;

            new ThreadStart(Publish).BeginInvoke(null, null);

            progressForm.Show(this);

            while (!_finished)
            {
                progressForm.Progress = _progress;
                progressForm.Label    = _file;
                progressForm.Refresh();
                Application.DoEvents();
                Thread.Sleep(10);
            }

            progressForm.Close();
            FrmMain_Load(null, null);

            MessageBox.Show("Autoupdate publish is complete", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 20
0
        private void GetFiles(string filePath, TreeNode node)
        {
            DirectoryInfo folder = new DirectoryInfo(filePath);

            treeView1.Invoke(new Action(delegate
            {
                node.Text = folder.Name;
                node.Tag  = "Folder";
                node.Name = folder.FullName.Replace(selectPath, string.Empty);
            }));


            FileInfo[] chldFiles = folder.GetFiles();
            foreach (FileInfo chlFile in chldFiles)
            {
                FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(chlFile.FullName);

                UpdateFileInfo fileInfo = new UpdateFileInfo
                {
                    FileName         = chlFile.Name,
                    FilePath         = chlFile.FullName.Replace(selectPath, string.Empty),
                    FileSize         = chlFile.Length,
                    MD5HashStr       = MD5Hash.GetMD5HashFromFile(chlFile.FullName),
                    FileVersion      = fvi.FileVersion,
                    VerificationType = MD5Hashs.Contains(chlFile.FullName.ToLower()) ? VerificationType.MD5Hash : VerificationType.Version
                };

                string config = string.Empty;

                if (chlFile.Name.ToLower().EndsWith("exe.config"))
                {
                    if (MainExe.ToLower() + ".config" == chlFile.Name.ToLower())
                    {
                        config = $"(配置文件,已忽略,配置项已记录)";
                        ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap()
                        {
                            ExeConfigFilename = chlFile.FullName
                        };
                        Configuration configuration            = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
                        Dictionary <string, string> dictionary = new Dictionary <string, string>();
                        foreach (var kv in configuration.AppSettings.Settings.AllKeys)
                        {
                            dictionary.Add(kv, configuration.AppSettings.Settings[kv].Value);
                        }
                        updateInfo.Configurations = dictionary;
                    }
                    else
                    {
                        config = $"(配置文件,已忽略)";
                    }
                }
                else
                {
                    fileinfos.Add(fileInfo);
                }



                TreeNode chldNode     = new TreeNode();
                string   verification = string.Empty;
                if (fileInfo.VerificationType == VerificationType.MD5Hash)
                {
                    verification = $":{fileInfo.MD5HashStr}";
                }
                string nodeText = !string.IsNullOrWhiteSpace(config) ? config : $"({fileInfo.FileVersion})({fileInfo.VerificationType}{verification})";
                chldNode.Text = $"{chlFile.Name} {nodeText}";
                chldNode.Tag  = fileInfo;

                treeView1.Invoke(new Action(delegate
                {
                    node.Nodes.Add(chldNode);
                    treeView1.ExpandAll();
                }));
            }
            DirectoryInfo[] chldFolders = folder.GetDirectories();
            foreach (DirectoryInfo chldFolder in chldFolders)
            {
                TreeNode chldNode = new TreeNode
                {
                    Text = folder.Name,
                    Tag  = "Folder",
                    Name = folder.FullName.Replace(selectPath, string.Empty)
                };
                treeView1.Invoke(new Action(delegate
                {
                    node.Nodes.Add(chldNode);
                    treeView1.ExpandAll();
                }));
                GetFiles(chldFolder.FullName, chldNode);
            }
        }
Ejemplo n.º 21
0
        public void CheckUpdateDoWork(object sender, DoWorkEventArgs e)
        {
            bool needUpdate = false;

            bool needCheck = false;

            switch (AppSettings.UpdateFrequency)
            {
            case 0:
                needCheck = true;
                break;

            case 1:
                if (AppSettings.LastUpdateRun.AddDays(1) < DateTime.Now)
                {
                    needCheck = true;
                }
                break;

            case 2:
                if (AppSettings.LastUpdateRun.AddDays(7) < DateTime.Now)
                {
                    needCheck = true;
                }
                break;
            }

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() && needCheck)
            {
                Processing.GetUpdaterVersion();
                Processing.GetAviSynthPluginsVer();

                WebClient downloader = new WebClient {
                    UseDefaultCredentials = true
                };
                Stream onlineUpdateFile;
                try
                {
                    onlineUpdateFile = downloader.OpenRead(new Uri("http://www.jt-soft.de/videoconvert/updatefile_7z.xml"));
                }
                catch (WebException exception)
                {
                    Log.Error(exception);
                    e.Result = false;
                    return;
                }

                if (onlineUpdateFile == null)
                {
                    e.Result = false;
                    return;
                }

                using (UpdateFileInfo updateFile = Updater.LoadUpdateFileFromStream(onlineUpdateFile))
                {
                    if (updateFile.Core.PackageVersion.CompareTo(AppSettings.GetAppVersion()) > 0)
                    {
                        needUpdate = true;
                    }

                    if (updateFile.Updater.PackageVersion.CompareTo(AppSettings.UpdaterVersion) > 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.AviSynthPlugins.PackageVersion, AppSettings.LastAviSynthPluginsVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.Profiles.PackageVersion, AppSettings.LastProfilesVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.X264.PackageVersion, AppSettings.Lastx264Ver) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.X26464.PackageVersion, AppSettings.Lastx26464Ver) != 0 &&
                        Environment.Is64BitOperatingSystem)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.FFMPEG.PackageVersion, AppSettings.LastffmpegVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.FFMPEG64.PackageVersion, AppSettings.Lastffmpeg64Ver) != 0 &&
                        Environment.Is64BitOperatingSystem)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.Eac3To.PackageVersion, AppSettings.Lasteac3ToVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.LsDvd.PackageVersion, AppSettings.LastlsdvdVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.MKVToolnix.PackageVersion, AppSettings.LastMKVMergeVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.Mplayer.PackageVersion, AppSettings.LastMplayerVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.TSMuxeR.PackageVersion, AppSettings.LastTSMuxerVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.MjpegTools.PackageVersion, AppSettings.LastMJPEGToolsVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.DVDAuthor.PackageVersion, AppSettings.LastDVDAuthorVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.MP4Box.PackageVersion, AppSettings.LastMp4BoxVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.HcEnc.PackageVersion, AppSettings.LastHcEncVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.OggEnc.PackageVersion, AppSettings.LastOggEncVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.OggEncLancer.PackageVersion, AppSettings.LastOggEncLancerVer) != 0 &&
                        AppSettings.UseOptimizedEncoders)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.Lame.PackageVersion, AppSettings.LastLameVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.VpxEnc.PackageVersion, AppSettings.LastVpxEncVer) != 0)
                    {
                        needUpdate = true;
                    }

                    if (String.CompareOrdinal(updateFile.BDSup2Sub.PackageVersion, AppSettings.LastBDSup2SubVer) != 0 &&
                        AppSettings.JavaInstalled)
                    {
                        needUpdate = true;
                    }
                }
            }

            if (needCheck && !needUpdate)
            {
                AppSettings.LastUpdateRun = DateTime.Now;
            }

            e.Result = needUpdate;
        }
Ejemplo n.º 22
0
        private void OnBeginUpdate()
        {
            try
            {
                BackupFile = new Dictionary <string, string>();
                UpdateFileInfo currentFileInfo = null;
                beginUpdate = true;
                if (NeedUpdateFile != null && NeedUpdateFile.Length > 0)
                {
                    Common.WriteLog_Information("开始更新进程,需要更新的文件数量:{0}", NeedUpdateFile.Length);
                    int thisFileIndex = 1;

                    download.Downloading += (s, e) =>
                    {
                        switch (e.DownloadState)
                        {
                        case DownloadState.BeginDownload:
                            BackupFile.Add(e.DownloadingFile.DownloadFile, e.DownloadingFile.BackupFile);
                            OnUpdateProgressing(new UpdateArgs(UpdateState.BeginDownload, currentFileInfo, NeedUpdateFile.Length, thisFileIndex, e));
                            break;

                        case DownloadState.Downloading:
                            OnUpdateProgressing(new UpdateArgs(UpdateState.Downloading, currentFileInfo, NeedUpdateFile.Length, thisFileIndex, e));
                            break;

                        case DownloadState.Downloaded:
                            OnUpdateProgressing(new UpdateArgs(UpdateState.Downloaded, currentFileInfo, NeedUpdateFile.Length, thisFileIndex, e));
                            break;
                        }
                    };


                    foreach (UpdateFileInfo updateFileInfo in NeedUpdateFile)
                    {
                        string currentFile = updateFileInfo.FilePath.Replace("\\", "/");
                        currentFileInfo = updateFileInfo;
                        OnUpdateProgressing(new UpdateArgs(UpdateState.Updating, updateFileInfo, NeedUpdateFile.Length, thisFileIndex));
                        string file = Path.Combine(Environment.CurrentDirectory, currentFile.TrimStart('/'));
                        string url  = string.Empty;
                        if (!Updater.UpdateUrl.EndsWith("/"))
                        {
                            url = Updater.UpdateUrl + currentFile;
                        }
                        else
                        {
                            url = Updater.UpdateUrl + currentFile.TrimStart('/');
                        }
                        Application.DoEvents();
                        download.HttpDownload(url, file);
                        thisFileIndex++;
                    }
                    OnUpdateProgressing(new UpdateArgs(UpdateState.Finish, null, NeedUpdateFile.Length, -1));
                }
            }
            catch (Exception ex)
            {
                beginUpdate    = false;
                this.Exception = Common.Exception <Exception>(ex.Message + Environment.NewLine + "错误代码:0x0f02");
                OnUpdateProgressing(new UpdateArgs(UpdateState.Error, null, NeedUpdateFile.Length, -1));
                OnRollbackUpdate();
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Has this file been downloaded already
 /// </summary>
 /// <param name="file">The file to check against</param>
 /// <returns>true if downloaded already</returns>
 public bool HasFile(UpdateFileInfo file)
 {
     return(SavedFiles.Any(f => f.Name == file.Name && f.Revision == file.Revision));
 }
Ejemplo n.º 24
0
 public bool equal(UpdateFileInfo other)
 {
     return(md5.Equals(other.md5));
 }
Ejemplo n.º 25
0
        /// <inheritdoc />
        public async Task UpdateAsync(ContentHash contentHash, bool touch, IClock clock, UpdateFileInfo updateFileInfo)
        {
            ContentDirectory.TryGetValue(contentHash, out var existingInfo);

            ContentFileInfo cloneInfo = null;

            if (existingInfo != null)
            {
                cloneInfo = new ContentFileInfo(existingInfo.FileSize, existingInfo.LastAccessedFileTimeUtc, existingInfo.ReplicaCount);
                if (touch)
                {
                    existingInfo.UpdateLastAccessed(clock);
                }
            }

            var updateTask = updateFileInfo(cloneInfo);

            if (updateTask != null)
            {
                var updateInfo = await updateTask;
                if (updateInfo != null)
                {
                    ContentDirectory.TryGetValue(contentHash, out existingInfo);
                    if (existingInfo == null)
                    {
                        ContentDirectory.TryAdd(contentHash, updateInfo);
                    }
                    else if (existingInfo.ReplicaCount != updateInfo.ReplicaCount)
                    {
                        ContentDirectory[contentHash].ReplicaCount = updateInfo.ReplicaCount;
                    }
                }
            }
        }
Ejemplo n.º 26
0
 private void stdFile_ExtractDone(IDataAcquire data)
 {
     UpdateFileInfo?.Invoke(data);
 }
Ejemplo n.º 27
0
        private async Task <byte[]> DownloadUpdatePackageAsync([NotNull] string clientDirectory, [NotNull] string newVersionPath, CancellationTokenSource cancellationTokenSource)
        {
            if (clientDirectory == null)
            {
                throw new ArgumentNullException("clientDirectory");
            }
            if (newVersionPath == null)
            {
                throw new ArgumentNullException("newVersionPath");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            if (_Logger.IsInfoEnabled)
            {
                _Logger.Info("Getting list of application files");
            }

            string[] excludedExtensions = { @".pdb", @".log" };

            var files = (from x in Directory.EnumerateFiles(clientDirectory, "*.*", SearchOption.TopDirectoryOnly)
                         let ext = Path.GetExtension(x)?.ToLowerInvariant()
                                   where !excludedExtensions.Contains(ext)
                                   let info = UpdateFileInfo.TryCreate(x, clientDirectory)
                                              where info != null
                                              select info).ToArray();

            if (_Logger.IsInfoEnabled)
            {
                _Logger.Info("Sending request to create update package.");
            }

            var package = await this.PostRequestAsync("Update/CreatePackage", new ExtendedFormUrlEncodedContent(new { files }), cancellationTokenSource) as byte[];

            if (_Logger.IsInfoEnabled)
            {
                _Logger.Info("Update package downloaded. Length = {0}", package?.LongLength ?? 0);
            }

            if (package == null)
            {
                return(null);
            }

            try
            {
                if (_Logger.IsDebugEnabled)
                {
                    _Logger.Debug("Saving update package");
                }

                File.WriteAllBytes(newVersionPath, package);

                if (_Logger.IsDebugEnabled)
                {
                    _Logger.Debug("The update package saved.");
                }
            }
            catch (Exception exp)
            {
                if (_Logger.IsWarnEnabled)
                {
                    _Logger.Warn(exp, "Error while saving the update package.");
                }
            }

            return(package);
        }