コード例 #1
0
        private List <UpdateTask> GetOldFileTasks(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource, FileIndex index)
        {
            List <UpdateTask> updateTasks = new List <UpdateTask>();

            for (int i = 0; i < index.files.Count; i++)
            {
                string curFile      = index.files[i];
                string curLocalFile = InstallationSettings.InstallationFolder + '/' + curFile;

                if (info.fileChecksums.ContainsKey(curFile))
                {
                    if (File.Exists(curLocalFile))
                    {
                        string curHash = FileHasher.GetFileChecksum(curLocalFile);
                        string updatedHash;
                        info.fileChecksums.TryGetValue(curFile, out updatedHash);

                        if (!curHash.Equals(updatedHash))
                        {
                            updateTasks.Add(new UpdateTask(TaskType.DownloadReplacementFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                        }
                    }
                    else
                    {
                        updateTasks.Add(new UpdateTask(TaskType.DownloadNewFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                    }
                }
                else
                {
                    updateTasks.Add(new UpdateTask(TaskType.DeleteFile, curLocalFile));
                }
            }
            return(updateTasks);
        }
コード例 #2
0
        private List <UpdateTask> GetNewFileTasks(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource, FileIndex index)
        {
            List <UpdateTask> updateTasks = new List <UpdateTask>();

            for (int i = 0; i < info.fileChecksums.Keys.Count; i++)
            {
                string curFile      = info.fileChecksums.Keys.ElementAt(i);
                string curLocalFile = InstallationSettings.InstallationFolder + '/' + curFile;

                if (index.files.Contains(curFile))
                {
                    //Already handled file
                    continue;
                }

                if (File.Exists(curLocalFile))
                {
                    //File exists but is missing in index?
                    string curHash = FileHasher.GetFileChecksum(curLocalFile);
                    string updatedHash;
                    info.fileChecksums.TryGetValue(curFile, out updatedHash);
                    if (updatedHash.Equals(curHash))
                    {
                        continue;
                    }
                    else
                    {
                        updateTasks.Add(new UpdateTask(TaskType.DownloadReplacementFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                    }
                }
                else
                {
                    updateTasks.Add(new UpdateTask(TaskType.DownloadNewFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                }
            }
            return(updateTasks);
        }