private Patch FormatAssistEditingPatch() { var lines = patchPanel.EditedLines.ToArray(); for (int i = 1; i < lines.Length; i++) { var l = lines[i]; if (l.Length == 0 || l[0] != ' ' && l[0] != '-' && l[0] != '+') { lines[i] = ' ' + l; } } Patch p; try { p = PatchFile.FromLines(lines, false).patches[0]; } catch (Exception e) { MessageBox.Show(this, e.Message, "Invalid Patch", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } p.RecalculateLength(); patchPanel.ReplaceEditedLines(p.ToString().GetLines()); return(p); }
public PatchList(string[] files, ASMEncodingUtility asmUtility) { FilePatches = new PatchFile[files.Length]; LoadedCorrectly = new bool[files.Length]; IList <AsmPatch> tryPatches; int i = 0; foreach (string file in files) { if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { AllPatches.AddRange(tryPatches); FilePatches[i] = new PatchFile(tryPatches.Count); FilePatches[i].filename = file; FilePatches[i].Patches.AddRange(tryPatches); LoadedCorrectly[i] = true; } else { LoadedCorrectly[i] = false; //MessageBox.Show(file.Substring(file.LastIndexOf("\\")) + " Did not load correctly"); } i++; } AllCheckStates = new CheckState[AllPatches.Count]; for (int j = 0; j < AllCheckStates.Length; j++) { AllCheckStates[j] = new CheckState(); AllCheckStates[j] = CheckState.Unchecked; } }
private void MergePatch_Load(object sender, EventArgs e) { PatchFile.Select(); RestorePosition("merge-patch"); Text = _applyPatchMsgBox.Text + " (" + Settings.WorkingDir + ")"; IgnoreWhitespace.Checked = Settings.ApplyPatchIgnoreWhitespace; }
/// <summary> /// Create a PatchData instance with data from a PatchFile instance /// </summary> /// <param name="File">The PatchFile instance to create PatchData from.</param> /// <returns>A new instance of PatchData.</returns> /// <remarks>TODO: I'm not sure what this was supposed to do; this is a guess.</remarks> public static PatchData ReadFile(PatchFile File) { PatchData _temp = new PatchData(); throw new NotImplementedException("TODO:"); //TODO WTF? }
public void ReloadFile(int index, ASMEncodingUtility asmUtility) { PatchFile patchFile = FilePatches[index]; IList <AsmPatch> tryPatches; List <Color> fileColorList = new List <Color>(); Color normalColor = Color.White; Color errorColor = Color.FromArgb(225, 125, 125); patchFile.Patches.Clear(); if (PatchXmlReader.TryGetPatches(File.ReadAllText(patchFile.Filename, Encoding.UTF8), patchFile.Filename, asmUtility, out tryPatches)) { foreach (AsmPatch patch in tryPatches) { if (!patch.IsHidden) { Color bgColor = string.IsNullOrEmpty(patch.ErrorText) ? normalColor : errorColor; patchFile.Patches.Add(patch); fileColorList.Add(bgColor); } } LoadedCorrectly[index] = true; } else { LoadedCorrectly[index] = false; } BackgroundColors[index + 1] = fileColorList.ToArray(); FileOrdinalMaps[index] = GetFileOrdinalMap(index); }
private void MergePatch_Load(object sender, EventArgs e) { PatchFile.Select(); Text = _applyPatchMsgBox.Text + " (" + Module.WorkingDir + ")"; IgnoreWhitespace.Checked = AppSettings.ApplyPatchIgnoreWhitespace; }
public PatchFile CreateFile() { PatchFile _temp = new PatchFile(); _temp.Data = new PatchData(); _temp.Data.Data = this.Data; return(_temp); }
/// <summary> /// 2. 创建Readme文件到输出目录 /// </summary> private void CreateReadmeFile(string[] allAssetBundles) { // 删除旧文件 string filePath = OutputPath + "/readme.txt"; if (File.Exists(filePath)) { File.Delete(filePath); } ShowBuildLog($"创建说明文件:{filePath}"); StringBuilder content = new StringBuilder(); AppendData(content, $"构建平台:{BuildTarget}"); AppendData(content, $"构建版本:{BuildVersion}"); AppendData(content, $"构建时间:{DateTime.Now}"); AppendData(content, ""); AppendData(content, $"--配置信息--"); for (int i = 0; i < BuildSettingData.Setting.Elements.Count; i++) { BuildSetting.Wrapper wrapper = BuildSettingData.Setting.Elements[i]; AppendData(content, $"FolderPath : {wrapper.FolderPath} || PackRule : {wrapper.PackRule} || NameRule : {wrapper.NameRule}"); } AppendData(content, ""); AppendData(content, $"--构建参数--"); AppendData(content, $"CompressOption:{CompressOption}"); AppendData(content, $"ForceRebuild:{IsForceRebuild}"); AppendData(content, $"DisableWriteTypeTree:{IsDisableWriteTypeTree}"); AppendData(content, $"IgnoreTypeTreeChanges:{IsIgnoreTypeTreeChanges}"); AppendData(content, ""); AppendData(content, $"--构建清单--"); for (int i = 0; i < allAssetBundles.Length; i++) { AppendData(content, allAssetBundles[i]); } AppendData(content, ""); AppendData(content, $"--更新清单--"); PatchFile patchFile = LoadPatchFile(); foreach (var pair in patchFile.Elements) { if (pair.Value.Version == BuildVersion) { AppendData(content, pair.Key); } } // 创建新文件 File.WriteAllText(filePath, content.ToString(), Encoding.UTF8); }
private void loadPatch(string fileName) { try { Logger("Loading file: " + fileName); System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(List <XmlPatch>)); System.IO.StreamReader file = new System.IO.StreamReader(fileName); List <XmlPatch> newPatchList = (List <XmlPatch>)reader.Deserialize(file); file.Close(); string CompOS = ""; if (newPatchList.Count > 0) { Logger("Description: " + newPatchList[0].Description); string[] OsList = newPatchList[0].CompatibleOS.Split(','); foreach (string OS in OsList) { if (CompOS != "") { CompOS += ","; } string[] Parts = OS.Split(':'); CompOS += Parts[0]; } if (!newPatchList[0].CompatibleOS.ToLower().StartsWith("table:") && !newPatchList[0].CompatibleOS.ToLower().StartsWith("search:")) { Logger("For OS: " + CompOS); } } bool isCompatible = false; for (int x = 0; x < newPatchList.Count; x++) { if (checkPatchCompatibility(newPatchList[x], basefile) < uint.MaxValue) { isCompatible = true; break; } } if (isCompatible || chkShowAll.Checked) { Logger("Patch is compatible"); PatchFile pFile = new PatchFile(); pFile.CompatibleOS = CompOS; pFile.Description = newPatchList[0].Description; pFile.FileName = fileName; pFile.Platform = newPatchList[0].XmlFile; patchFileList.Add(pFile); } } catch (Exception ex) { LoggerBold(ex.Message); } }
/// <summary> /// Compare two PatchFile instances to see if a file needs to be downloaded. /// </summary> /// <param name="Patch">The PatchFile in the server manifest.</param> /// <param name="Client">The PatchFile in the client manifest.</param> /// <returns>True if the file needed to be downloaded, false otherwise.</returns> private bool NeedToDownloadFile(PatchFile Patch, PatchFile Client) { string PatchName = Path.GetFileName(RelativePath + Patch.Address); string ClientName = Path.GetFileName(RelativePath + Patch.Address); if ((Patch.FileHash != Client.FileHash) || (PatchName != ClientName)) { return(true); } return(false); }
private void QueueFileUpload(PatchFile asset, FileCompressionMode compress) { var info = new FileUploadInfo() { File = asset, Compress = compress, LocalFile = Path.Combine(Program.Config.PatcherFilesPath, asset.Name) }; lock (_uploadQueue) _uploadQueue.Enqueue(info); }
private PatchFile[] InitPatchFilesFromDB() { using (var reader = (MySqlDataReader)_connection.RunQuery($@"SELECT * FROM `{PATCHES_TABLE}`")) { var patches = new List <PatchFile>(); while (reader.Read()) { patches.Add(PatchFile.TryParseRow(reader)); } return(patches.OrderBy(x => x.ID).ToArray()); } }
public void LoadFile() { _defaultSetsContent = SetsFile.ReadAllBytes(); _customSetContents = CustomSetCodes .Select(code => AppDir.Data.Join("custom_sets", code + ".json").ReadAllBytes()) .ToArray(); Patch = JsonConvert.DeserializeObject <Patch>(PatchFile.ReadAllText()); Patch.IgnoreCase(); IsFileLoadingComplete.Signal(); }
private PatchFile ReadPatchFile(XElement item) { PatchFile result = new PatchFile { Filename = XElementExtender.ReadName(item), DownloadUri = XElementExtender.ReadUri(item), LocalDirectory = XElementExtender.ReadPath(item), Hash = XElementExtender.ReadHash(item) }; OutputConsole.PrintVerbose(result, 5); return(result); }
public PatchData(string[] files, ASMEncodingUtility asmUtility) { FilePatches = new PatchFile[files.Length]; LoadedCorrectly = new bool[files.Length]; IList <AsmPatch> tryPatches; List <Color> allColorList = new List <Color>(); Color normalColor = Color.White; Color errorColor = Color.FromArgb(225, 125, 125); BackgroundColors = new Color[files.Length + 1][]; for (int index = 0; index < files.Length; index++) { string file = files[index]; List <Color> fileColorList = new List <Color>(); FilePatches[index] = new PatchFile(file); if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { foreach (AsmPatch patch in tryPatches) { if (!patch.IsHidden) { Color bgColor = string.IsNullOrEmpty(patch.ErrorText) ? normalColor : errorColor; FilePatches[index].Patches.Add(patch); fileColorList.Add(bgColor); AllPatches.Add(patch); if (!patch.HideInDefault) { AllShownPatches.Add(patch); allColorList.Add(bgColor); } } } LoadedCorrectly[index] = true; } else { LoadedCorrectly[index] = false; } BackgroundColors[index + 1] = fileColorList.ToArray(); } BackgroundColors[0] = allColorList.ToArray(); BuildOrdinalMaps(); }
/// <summary> /// 3. 复制更新文件到补丁目录 /// </summary> private void CopyUpdateFiles() { string packagePath = GetPackagePath(); ShowBuildLog($"开始复制更新文件到版本目录:{packagePath}"); // 复制Readme文件 { string sourcePath = $"{OutputPath}/readme.txt"; string destPath = $"{packagePath}/readme.txt"; EditorTools.CopyFile(sourcePath, destPath, true); ShowBuildLog($"复制Readme文件到:{destPath}"); } // 复制补丁文件 { string sourcePath = $"{OutputPath}/{PatchDefine.StrBuildPackageFileName}"; string destPath = $"{packagePath}/{PatchDefine.StrBuildPackageFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); ShowBuildLog($"复制Package文件到:{destPath}"); } // 复制Manifest文件 { string sourcePath = $"{OutputPath}/{PatchDefine.StrBuildManifestFileName}"; string destPath = $"{packagePath}/{PatchDefine.StrBuildManifestFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); ShowBuildLog($"复制Manifest文件到:{destPath}"); } // 复制Manifest文件 { string sourcePath = $"{OutputPath}/{PatchDefine.StrBuildManifestFileName}.manifest"; string destPath = $"{packagePath}/{PatchDefine.StrBuildManifestFileName}.manifest"; EditorTools.CopyFile(sourcePath, destPath, true); } // 复制所有更新文件 PatchFile patchFile = LoadPatchFile(); foreach (var pair in patchFile.Elements) { if (pair.Value.Version == BuildVersion) { string sourcePath = $"{OutputPath}/{pair.Key}"; string destPath = $"{packagePath}/{pair.Key}"; EditorTools.CopyFile(sourcePath, destPath, true); ShowBuildLog($"复制更新文件:{destPath}"); } } }
/// <summary> /// Open a PATCH file from the FileInfo given. /// </summary> /// <param name="file"></param> private void OpenPATCH(FileInfo file) { Log.WriteLine("Opening PATCH: " + file.Name); infoText.Text = "Opening PATCH.."; PatchFile patch; using (BinaryReader reader = new BinaryReader(File.Open(file.FullName, FileMode.Open))) { patch = new PatchFile(); patch.file = file; patch.Deserialize(reader, Gibbed.IO.Endian.Little); } }
/// <summary> /// Open a PATCH file from the FileInfo given. /// </summary> /// <param name="file"></param> private void OpenPATCH(FileInfo file) { Log.WriteLine("Opening PATCH: " + file.Name); infoText.Text = "Opening PATCH.."; PatchFile patch; using (var input = File.OpenRead(file.FullName)) { patch = new PatchFile(); patch.file = file; patch.Deserialize(input, Gibbed.IO.Endian.Big); } }
public async Task <ActionResult <Patch> > Post([FromBody] PatchFile patchFile) { try { Data.Models.Patch existingPatch = await context.Patches .Include(x => x.Tags) .Include(x => x.Ratings) .Include(x => x.AppUser) .Include(x => x.NufUser) .Include(x => x.PatchFiles) .ThenInclude(pf => pf.File) .OrderByDescending(x => x.DateCreated) .SingleOrDefaultAsync(x => x.Id == patchFile.PatchId); existingPatch.PatchFiles.Add(new Data.Models.PatchFile { FileId = patchFile.FileId, PatchId = patchFile.PatchId }); await context.SaveChangesAsync(); cache.Remove(Constants.PatchCacheKey); cache.Remove(Constants.FileCacheKey); Data.Models.Patch updatedPatch = await context.Patches .Include(x => x.Tags) .Include(x => x.Ratings) .Include(x => x.AppUser) .Include(x => x.NufUser) .Include(x => x.PatchFiles) .ThenInclude(pf => pf.File) .OrderByDescending(x => x.DateCreated) .SingleOrDefaultAsync(x => x.Id == patchFile.PatchId); var model = mapper.Map <Patch>(updatedPatch); return(CreatedAtAction("Post", model)); } catch (Exception e) { logger.LogError(e, "An error occurred creating the DB connection."); return(BadRequest()); } }
public static IEnumerable <PatchItem> Load(PatchFile source) { using StreamReader reader = File.OpenText(source.Filename); var options = new CsvOptions { HeaderMode = source.HeaderMode, RowsToSkip = source.RowsToSkip, Separator = source.Separator[0] }; foreach (var row in CsvReader.Read(reader, options)) { var data = new PatchItem { From = new GeoEntityId { DataType = row[0], Reference = row[1], Name = row[2] }, To = new GeoEntityId { DataType = row[3], Reference = row[4], Name = row[5] } }; yield return(data); } }
/// <summary> /// 加载补丁文件从输出目录 /// </summary> private PatchFile LoadPatchFile() { string filePath = $"{OutputPath}/{PatchDefine.StrBuildPackageFileName}"; PatchFile patchFile = new PatchFile(); // 如果文件不存在 if (File.Exists(filePath) == false) { return(patchFile); } using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { StreamReader sr = new StreamReader(fs); patchFile.Parse(sr); sr.Close(); fs.Close(); } return(patchFile); }
public FilePatcherViewModel(FilePatcher filePatcher, string commonBasePath) { fp = filePatcher; rejectsFilePath = Path.ChangeExtension(fp.patchFilePath, "rej"); rejectsFile = File.Exists(rejectsFilePath) ? PatchFile.FromText(File.ReadAllText(rejectsFilePath), verifyHeaders: false) : new PatchFile(); var label = fp.patchFile.basePath; if (commonBasePath != null && label.StartsWith(commonBasePath)) { label = label.Substring(commonBasePath.Length); } Label = label; Children = (ListCollectionView)CollectionViewSource.GetDefaultView(_results); Children.SortDescriptions.Add(new SortDescription { PropertyName = nameof(ResultViewModel.Start1), Direction = ListSortDirection.Ascending }); Children.IsLiveSorting = true; ((INotifyCollectionChanged)Children).CollectionChanged += ResultsMoved; UpdateResults(); }
public PatchList(string[] files, ASMEncodingUtility asmUtility) { FilePatches = new PatchFile[files.Length]; LoadedCorrectly = new bool[files.Length]; IList<AsmPatch> tryPatches; int i = 0; foreach (string file in files) { if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { AllPatches.AddRange(tryPatches); FilePatches[i] = new PatchFile(tryPatches.Count); FilePatches[i].filename = file; FilePatches[i].Patches.AddRange(tryPatches); LoadedCorrectly[i] = true; } else { LoadedCorrectly[i] = false; //MessageBox.Show(file.Substring(file.LastIndexOf("\\")) + " Did not load correctly"); } i++; } AllCheckStates = new CheckState[AllPatches.Count]; for (int j = 0; j < AllCheckStates.Length; j++) { AllCheckStates[j] = new CheckState(); AllCheckStates[j] = CheckState.Unchecked; } }
public static PatchFile TryParsePatchFile(string filename) { if (Path.GetExtension(filename) != ".sql") { return(null); } var lines = File.ReadAllLines(filename); var currentState = ParsingState.JustStarted; var pf = new PatchFile(); foreach (var line in lines) { if (line == SEPERATOR_SCRIPT_UP) { currentState = ParsingState.ScriptUp; continue; } if (line == SEPERATOR_SCRIPT_DOWN) { currentState = ParsingState.ScriptDown; continue; } switch (currentState) { case ParsingState.JustStarted: // Ignoring line... continue; case ParsingState.ScriptDown: pf.ScriptDown += line + "\r\n"; break; case ParsingState.ScriptUp: pf.ScriptUp += line + "\r\n"; break; } } if (currentState == ParsingState.JustStarted) { throw new Exception("Did not find seperators. Script: " + filename); } pf.ScriptUp = CleanupString(pf.ScriptUp); pf.ScriptDown = CleanupString(pf.ScriptDown); if (pf.ScriptUp == null && pf.ScriptDown == null) { throw new Exception("Did not initialize a Down or Up script. Script: " + filename); } if (pf.ScriptDown != null && pf.ScriptUp == null) { throw new Exception("Found Down script, but no Up script. Script: " + filename); } pf.ID = int.Parse(Path.GetFileNameWithoutExtension(filename)); pf.CalculateFileHash(); pf.State = PatchingState.LocalFile; return(pf); }
/// <summary> /// 1. 创建补丁文件到输出目录 /// </summary> private void CreatePackageFile(string[] allAssetBundles) { // 加载旧文件 PatchFile patchFile = LoadPatchFile(); // 删除旧文件 string filePath = OutputPath + $"/{PatchDefine.StrBuildPackageFileName}"; if (File.Exists(filePath)) { File.Delete(filePath); } // 创建新文件 ShowBuildLog($"创建补丁文件:{filePath}"); using (FileStream fs = File.Create(filePath)) { StreamWriter sw = new StreamWriter(fs); // 写入版本信息 sw.Write(BuildVersion); sw.Write("\n"); sw.Flush(); // 写入Manifest文件的信息 { string assetName = PatchDefine.StrBuildManifestFileName; string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeKB = EditorTools.GetFileSize(path) / 1024; int version = BuildVersion; sw.Write($"{assetName}={md5}={sizeKB}={version}"); sw.Write("\n"); sw.Flush(); } // 写入所有AssetBundle文件的信息 foreach (string assetName in allAssetBundles) { string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeKB = EditorTools.GetFileSize(path) / 1024; int version = BuildVersion; // 注意:如果文件没有变化使用旧版本号 PatchElement element; if (patchFile.Elements.TryGetValue(assetName, out element)) { if (element.MD5 == md5) { version = element.Version; } } sw.Write($"{assetName}={md5}={sizeKB}={version}"); sw.Write("\n"); sw.Flush(); } // 关闭文件流 sw.Close(); fs.Close(); } }
public override bool TryApplyPatch(out string failureReason) { string path = Directory.GetFiles(GameDirectory, Chunk + ".pak", SearchOption.AllDirectories).FirstOrDefault(); if (path == null) { failureReason = $"Can't find pak file '{Chunk}.pak'"; return(false); } var replacementFile = PatchFile.GetEntry(ReplacementFileName); if (replacementFile == null) { failureReason = $"Missing file '{ReplacementFileName}' in patch"; return(false); } using (var pak = Pak.OpenAsync(path).Result) { if (pak.IsIndexEncrypted) { failureReason = "Pak must be decrypted first"; return(false); } foreach (var entry in pak.GetEntriesAsync().Result) { if (entry.FileName == FileName) { using (var stream = replacementFile.Open()) using (var ms = new MemoryStream()) { stream.CopyTo(ms); if (ms.Length > entry.Size) { failureReason = "Replacement file is bigger than the original file"; return(false); } else if (ms.Length < entry.Size) { long padSize = entry.Size - ms.Length; for (long i = 0; i < padSize; i++) { ms.WriteByte(Padding == PaddingType.Spaces ? (byte)0x20 : (byte)0x00); } } ms.Seek(0, SeekOrigin.Begin); var task = pak.SwapEntryAsync(entry, ms); task.Wait(); failureReason = ""; return(true); } } } failureReason = $"Cannot find file '{FileName}' in pak '{Chunk}.pak'"; return(false); } }