public RegularFileProperties(RegularFileEntry entry)
        {
            InitializeComponent();

            this.Entry = entry;
            this.isCompressedCheckBox.Checked = this.Entry.Compressed;
        }
Ejemplo n.º 2
0
        public static void ImportFiles(DirectoryEntry entry)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in fileDialog.FileNames)
                {
                    if (entry.GetEntries().Any(e => e.Name == Path.GetFileName(file)))
                    {
                        // TODO: Ask for overwrite
                        MessageBox.Show(String.Format("Error: file {0} already exists.", Path.GetFileName(file)));
                        return;
                    }
                }
                foreach (String file in fileDialog.FileNames)
                {
                    // TODO: add resources, decide if to compress or not, all by extentions.
                    // Right now all regular files compressed by default
                    RegularFileEntry addedFile = new RegularFileEntry(Path.GetFileName(file), new ExternalFileStreamCreator(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)), true);
                    entry.AddEntry(addedFile);
                    if (entry.FilesListView != null)
                    {
                        entry.FilesListView.Items.Add(new EntryListViewItem(addedFile));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void importButton_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in filesDataView.Rows)
            {
                string filename     = (string)row.Cells[0].Value;
                int    lastDirSplit = filename.LastIndexOfAny(new char[] { '\\', '/' });
                string baseFilename = filename.Substring(lastDirSplit + 1);
                string baseFolder   = "";

                if (lastDirSplit != -1)
                {
                    baseFolder = filename.Substring(lastDirSplit);
                }

                string operation  = (string)row.Cells[1].Value;
                string type       = (string)row.Cells[2].Value;
                bool   compressed = (bool)row.Cells[3].Value;

                if (operation != "Skip")
                {
                    string filepath = Path.GetTempFileName();
                    // Let's copy the file to temp folder, this file will be deleted on close
                    FileStream writeStream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 0x1000, FileOptions.DeleteOnClose);
                    Files[filename].Seek(0, SeekOrigin.Begin);
                    Files[filename].CopyTo(writeStream);

                    // Close the stream
                    Files[filename].Close();
                    Files.Remove(filename);

                    // Take an handle to the file, so it will be delete only when this handle will be closed.
                    FileStream readStream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
                    writeStream.Close();

                    FileEntry entry;
                    if (type == "File")
                    {
                        entry = new RegularFileEntry(baseFilename, new ExternalFileStreamCreator(readStream), compressed);
                    }
                    else
                    {
                        // We already checked that the file is fine
                        Structs.RSC7Header rsc7header = new Structs.RSC7Header(readStream);
                        // is resouce
                        entry = new ResourceEntry(baseFilename, new RSC7StreamCreator(readStream), rsc7header.SystemFlag, rsc7header.GraphicsFlag);
                    }

                    // Ensure the directory of the file. the file going to have directory in case of importing whole directory tree.
                    if (baseFolder != "")
                    {
                        DirectoryEntry lastDirectory = this.Entry;
                        foreach (string directoryPart in baseFolder.Split(new char[] { '\\', '/' }))
                        {
                            if (lastDirectory.GetEntry(directoryPart) == null)
                            {
                                lastDirectory.AddEntry(new DirectoryEntry(directoryPart, new List <Entry>()));
                            }
                            lastDirectory = lastDirectory.GetEntry(directoryPart) as DirectoryEntry;
                        }
                    }

                    DirectoryEntry realDirectory = ((DirectoryEntry)this.Entry.GetEntry(baseFolder));

                    if (operation == "Replace")
                    {
                        FileEntry oldEntry = this.Entry.GetEntry(filename) as FileEntry;
                        oldEntry.Parent.RemoveEntry(oldEntry);
                    }
                    realDirectory.AddEntry(entry);
                }
            }
            Close();
        }