public void AddFile(string filename) { bool skipFile = false; bool isReplace = false; bool isRSC7 = false; bool isCompressed = true; FileStream stream = null; // TODO: Add an explnation on why couldn't add file // TODO: check all the features here (adding a folder..) // Let's try to open the file, we are going to lock the files until the end of the dialog, so thier state won't change try { stream = File.OpenRead(Path.Combine(this.DirectoryPath, filename)); Files[filename] = stream; } catch (Exception) { skipFile = true; } if (!skipFile) { try { Structs.RSC7Header rsc7Header = new Structs.RSC7Header(stream); // Test the size of the resource if (ResourceEntry.GetSizeFromSystemFlag(rsc7Header.SystemFlag) + ResourceEntry.GetSizeFromGraphicsFlag(rsc7Header.GraphicsFlag) + 0x10 == stream.Length) { isRSC7 = true; } } catch (Exception) { if (stream.Length <= 0x100) { // small files aren't compressed isCompressed = false; } else { isCompressed = FileShouldBeCompressed(filename); } } } if (!skipFile) { // Check if the directory of the entry is a regular existing file.. int lastDirSplit = filename.LastIndexOfAny(new char[] { '\\', '/' }); if (lastDirSplit != -1) { string baseFolder = filename.Substring(lastDirSplit); DirectoryEntry lastDirectory = this.Entry; foreach (string directoryPart in baseFolder.Split(new char[] { '\\', '/' })) { if (lastDirectory.GetEntry(directoryPart) == null) { // that is fine, there is no entry like that yet break; } lastDirectory = lastDirectory.GetEntry(directoryPart) as DirectoryEntry; if (lastDirectory == null) { // oh, that is not a directory, that is bad. skipFile = true; } } } } if (!skipFile) { // Check if there is already entry with that name Entry originalEntry = this.Entry.GetEntry(filename); // TODO: maybe copy the proporties from the coppied object? if (originalEntry != null) { if (originalEntry is DirectoryEntry) { skipFile = true; } else { isReplace = true; } } // Check if file should be compressed } // let's build the row DataGridViewRow row = new DataGridViewRow(); var filenameCell = new DataGridViewTextBoxCell(); var operationCell = new DataGridViewComboBoxCell(); var typeCell = new DataGridViewComboBoxCell(); var compressedCell = new DataGridViewCheckBoxCell(); var encryptedCell = new DataGridViewCheckBoxCell(); var isRSC7Cell = new DataGridViewCheckBoxCell(); row.Cells.Add(filenameCell); row.Cells.Add(operationCell); row.Cells.Add(typeCell); row.Cells.Add(compressedCell); row.Cells.Add(encryptedCell); row.Cells.Add(isRSC7Cell); filenameCell.Value = filename; if (!skipFile) { if (isReplace) { operationCell.Items.Add("Replace"); operationCell.Value = "Replace"; } else { operationCell.Items.Add("Add"); operationCell.Value = "Add"; } } else { operationCell.Value = "Skip"; compressedCell.ReadOnly = true; encryptedCell.ReadOnly = true; } operationCell.Items.Add("Skip"); typeCell.Items.Add("File"); if (isRSC7) { typeCell.Items.Add("Resource"); typeCell.Value = "Resource"; // TODO: If it is changed to File, it isn't can't be changed.. compressedCell.Value = true; compressedCell.ReadOnly = true; } else { typeCell.Value = "File"; compressedCell.Value = isCompressed; } isRSC7Cell.Value = isRSC7; filesDataView.Rows.Add(row); }
// Ignore first 0x10, it is supposed to be the header, but is it junk since we got all the information that we need about the resource from the flags? public ResourceStreamCreator(Stream fileStream, long offset, int compressedSize, uint systemFlag, uint graphicsFlag, string resourceType) : base(fileStream, offset + 0x10, compressedSize - 0x10, (int)(ResourceEntry.GetSizeFromSystemFlag(systemFlag) + ResourceEntry.GetSizeFromGraphicsFlag(graphicsFlag)), ResourceEntry.IsResourceEncrypted(resourceType)) { }
// Ignore first 0x10, it is supposed to be the header, but is it junk since we got all the information that we need about the resource from the flags? public ResourceStreamCreator(RPF7File file, long offset, int compressedSize, uint systemFlag, uint graphicsFlag) : base(file, offset + 0x10, compressedSize - 0x10, (int)(ResourceEntry.GetSizeFromSystemFlag(systemFlag) + ResourceEntry.GetSizeFromGraphicsFlag(graphicsFlag)), ResourceEntry.IsResourceEncrypted(ResourceEntry.GetResourceTypeFromFlags(systemFlag, graphicsFlag))) { }