private void AddEntries(Dictionary <byte[], TradDictEntry> dictionary) { foreach (var alteredEntry in Command.AddedEntries) { byte[] hash = null; if (alteredEntry.Key != null) { hash = MiscUtilities.HexByteStringToByteArray(alteredEntry.Key); } else { do { hash = GenerateEntryHash(); }while (dictionary.ContainsKey(hash)); } //Alter if exists otherwise add a new one. TradDictEntry entry; if (dictionary.TryGetValue(hash, out entry)) { entry.Content = alteredEntry.Value; } else { entry = new TradDictEntry(); entry.Content = alteredEntry.Value; entry.ContentLength = (uint)alteredEntry.Value.Length; entry.Hash = hash; dictionary.Add(hash, entry); } } }
private void RemoveEntries(Dictionary <byte[], TradDictEntry> dictionary) { foreach (var entryHash in Command.RemovedEntries) { var hash = MiscUtilities.HexByteStringToByteArray(entryHash); if (!dictionary.Remove(hash)) { var warning = String.Format("RemoveEntry operation failed " + "because entry with the given hash \"{0}\" wasn't found.", entryHash); Common.Logging.LoggerFactory.Create(this.GetType()).Warn(warning); } } }
protected override void ExecuteCommandsLogic(CmdsExecutionData data) { if (!data.ContainerFile.ContainsContentFileWithPath(data.ContentPath)) { TgvImage image = DDSFileToTgv(data.ModificationSourcePath, !Command.UseMipMaps); //Trzeba mieć na to oko, czy nie powoduje problemów, bo przy replace była używana checksuma starego obrazka. image.SourceChecksum = !String.IsNullOrEmpty(Command.Checksum) ? MiscUtilities.HexByteStringToByteArray(Command.Checksum) : image.ComputeContentChecksum(); image.IsCompressed = Command.UseCompression; var newContentFile = new EdataContentFile(); newContentFile.Path = data.ContentPath; newContentFile.LoadCustomContent(TgvToBytes(image, !Command.UseMipMaps)); data.ContainerFile.AddContentFile(newContentFile); } else if (Command.OverwriteIfExist) { var contentFile = data.ContainerFile.GetContentFileByPath(data.ContentPath); //To nie będzie potrzebne tutaj jeśli nie bedzie trzeba ładować i wykorzystywać starego obrazka. if (contentFile.FileType != ContentFileType.Image) { throw new CmdExecutionFailedException( String.Format("Invalid targetContentPath: \"{0}\". It doesn't target an image content file.", data.ContentPath), DefaultExecutionErrorMsg); } //Ładowanie starego obrazka nie będzie potrzebne jeśli bedzie pewnośc ze recznie wygenerowana checkusma jest ok. //Ok, tu kiedyś było odczytywanie starych danych z starego obrazka, teraz checksuma jest generowana na nowo, //żeby uniknac konieczności ładowania tych starych danych, bo nie sa potrzeben przy dodawaniu, a tutaj były by potrzebne //i trudno to rozwiązać przy założeniu ze dane są ładowane na zewnątrz. //TgvImage oldTgv = BytesToTgv(contentFile.Content); TgvImage image = DDSFileToTgv(data.ModificationSourcePath, !Command.UseMipMaps); image.SourceChecksum = !String.IsNullOrEmpty(Command.Checksum) ? MiscUtilities.HexByteStringToByteArray(Command.Checksum) : image.ComputeContentChecksum(); image.IsCompressed = Command.UseCompression; contentFile.LoadCustomContent(TgvToBytes(image, !Command.UseMipMaps)); } }
private void RenameEntries(Dictionary <byte[], TradDictEntry> dictionary) { foreach (var entryToRename in Command.RenamedEntries) { var hash = MiscUtilities.HexByteStringToByteArray(entryToRename.Key); TradDictEntry entry; if (dictionary.TryGetValue(hash, out entry)) { entry.Content = entryToRename.Value; } else { var warning = String.Format("RenameEntry operation failed because " + "entry with the given hash \"{0}\" wasn't found.", entryToRename.Key); Common.Logging.LoggerFactory.Create(this.GetType()).Warn(warning); } } }