private void OpenDatFile(string pathDat) { string message; if (!DATManage.OpenDatFile(pathDat, out message)) { MessageBox.Show(message, "Open Error"); return; } OpenDat dat = ControlDat.OpeningDat(pathDat); if (currentDat == null) { currentDat = dat.DatName; } BuildTree(dat); if (currentNode != null) { currentNode.ForeColor = Color.White; } TreeNode[] node = folderTreeView.Nodes.Find(dat.DatName, false); SelectTreeNode(node[0]); folderTreeView.SelectedNode = node[0]; totalToolStripStatusLabel.Text = dat.TotalFiles.ToString(); }
private void CreateNew(DAT.FalloutType type) { if (CreateNewDatDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } string newDat = CreateNewDatDialog.FileName; if (newDat == string.Empty) { return; } if (ControlDat.DatIsOpen(newDat)) { MessageBox.Show((LocaleRU) ? "Данный DAT файл уже открыт!" : "This DAT file is already open!"); return; } DATManage.CreateDatFile(newDat, type); OpenDat dat = ControlDat.OpeningDat(newDat, true); // empty BuildTree(dat); if (currentNode != null) { currentNode.ForeColor = Color.White; } TreeNode[] node = folderTreeView.Nodes.Find(dat.DatName, false); SelectTreeNode(node[0]); folderTreeView.SelectedNode = node[0]; totalToolStripStatusLabel.Text = "0"; }
private void tsBtnSearch_Click(object sender, EventArgs e) { if (currentDat == null) { return; } if (stbFindFile.Text.Length <= 1) { stbFindFile.BackColor = Color.MistyRose; return; } List <sFile> list = ControlDat.GetDat(currentDat).FindFilesByPattern(stbFindFile.Text); if (list.Count == 0) { stbFindFile.BackColor = Color.MistyRose; return; } FindFilesListForm listForm = new FindFilesListForm(list); listForm.GotoFile += GotoListFile; listForm.Show(this); }
string createFolderPath; // путь с сохранением регистра private void CreateFolder() { int num = 0; exist: TreeNode addNode = new TreeNode((num == 0) ? "NewFolder" : "NewFolder" + num.ToString()); string fullPath = Misc.GetNodeFullPath(currentNode); if (fullPath.Length > currentDat.Length) { createFolderPath = fullPath.Substring(currentDat.Length + 1) + "\\"; } createFolderPath += addNode.Text + "\\"; OpenDat dat = ControlDat.GetDat(currentDat); if (dat.FolderExist(createFolderPath)) { num++; addNode = null; goto exist; } currentNode.Nodes.Add(addNode); currentNode.Expand(); folderTreeView.SelectedNode = addNode; createFolder = true; SelectTreeNode(addNode); folderTreeView.LabelEdit = true; folderTreeView.SelectedNode.BeginEdit(); }
private void OpenDat(string pathDat) { if (ControlDat.DatIsOpen(pathDat)) { MessageBox.Show((LocaleRU) ? "Этот DAT файл уже открыт!" : "This DAT file is already open!"); return; } OpenDatFile(pathDat); }
private void ImportFilesWithFolders(string[] list, string rootFolder) { OpenDat dat = ControlDat.GetDat(currentDat); string treeFolder = GetCurrentTreeFolder(); foreach (var file in list) { if (rootFolder != null) { string folder = file.Substring(rootFolder.Length); int i = folder.LastIndexOf('\\') + 1; folder = folder.Remove(i); if (folder.Length > 0) { if (treeFolder.Length > 0) { //if (folder[0] != '\\') // folder = folder.Insert(0, "\\"); // добавить в начало } else { if (folder[0] == '\\') { folder = folder.Substring(1); // удалить '\' в начале } } } dat.AddVirtualFile(file, treeFolder + folder); } else { if (treeFolder.Length > 0) { dat.AddVirtualFile(file, treeFolder + '\\'); } else { dat.AddVirtualFile(file, treeFolder); } } } dat.OverwriteAll = false; // обновление списка if (rootFolder != null) { ReBuildTreeNode(dat); } if (treeFolder.Length > 0) { treeFolder += '\\'; } FindFiles(currentDat, treeFolder); SaveToolStripButton.Enabled = true; }
/// <summary> /// Распаковывает список файлов с /// </summary> /// <param name="listFiles"></param> /// <param name="extractToPath"></param> /// <param name="cutPath"></param> private void ExtractFiles(string[] listFiles, string extractToPath, string cutPath) { successExtracted = 0; statusToolStripStatusLabel.Text = "Extracted:"; toolStripProgressBar.Maximum = (listFiles != null) ? listFiles.Length : ControlDat.GetDat(currentDat).TotalFiles; new WaitForm(this).Unpack(extractToPath, listFiles, currentDat, cutPath); textToolStripStatusLabel.Text = successExtracted + " of " + toolStripProgressBar.Maximum + " files."; toolStripProgressBar.Value = 0; }
private void CloseDat() { if (currentDat != null && folderTreeView.SelectedNode != null && MessageBox.Show(this, String.Format((LocaleRU) ? "Вы действительно хотите закрыть\n{0} файл?" : "Do you want to close\n{0} file?", currentDat), "Dat Explorer II", MessageBoxButtons.YesNo) == DialogResult.Yes) { ControlDat.CloseDat(currentDat); currentDat = null; filesListView.Items.Clear(); folderTreeView.Nodes.RemoveAt(Misc.GetRootNode(folderTreeView.SelectedNode).Index); closeToolStripButton.Enabled = (folderTreeView.Nodes.Count > 0); } }
private void folderTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { folderTreeView.LabelEdit = false; OpenDat dat = ControlDat.GetDat(currentDat); if (createFolder) { dat.AddEmptyFolder(createFolderPath); e.Node.Name = createFolderPath.ToLowerInvariant(); createFolderPath = null; createFolder = false; } if (e.Label == null) { return; } if (e.Label.Equals(e.Node.Text)) { e.CancelEdit = true; return; } string folderPath = e.Node.Name; // in lower case; int i = folderPath.LastIndexOf(e.Node.Text.ToLowerInvariant() + '\\'); string renameFolderPath = folderPath.Remove(i) + e.Label + '\\'; if (dat.FolderExist(renameFolderPath, false)) { MessageBox.Show((LocaleRU) ? "Директория с таким именем уже существует." : "This directory already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; return; } e.Node.Name = renameFolderPath.ToLowerInvariant(); dat.RenameFolder(folderPath, e.Label); SaveToolStripButton.Enabled = dat.ShouldSave(); dirToolStripStatusLabel.Text = "Directory: " + e.Node.Name; }
internal void DeleteFiles(string path) { List <String> listFiles = new List <String>(); GetFolderFiles(listFiles, path); OpenDat dat = ControlDat.GetDat(currentDat); if (listFiles.Count > 0) { toolStripProgressBar.Maximum = listFiles.Count; dat.DeleteFile(listFiles, true); } else { dat.RemoveEmptyFolder(path); } }
private void SelectTreeNode(TreeNode node) { upToolStripButton.Enabled = (node.Parent != null); currentNode = node; node.ForeColor = Color.Yellow; string datPath = Misc.GetDatName(node); if (currentDat != datPath) { SaveToolStripButton.Enabled = ControlDat.GetDat(datPath).ShouldSave(); SaveToolStripButton.ToolTipText = "Save: " + datPath; } currentDat = datPath; FindFiles(datPath, node); extractFolderToolStripMenuItem.Enabled = true; closeToolStripButton.Enabled = true; }
private void ImportFiles(string[] list) { OpenDat dat = ControlDat.GetDat(currentDat); string treeFolder = GetCurrentTreeFolder(); if (treeFolder.Length > 0) { treeFolder += '\\'; } foreach (var file in list) { dat.AddVirtualFile(file, treeFolder); } dat.OverwriteAll = false; // обновление списка FindFiles(currentDat, treeFolder); SaveToolStripButton.Enabled = true; }
private void SaveToolStripButton_Click(object sender, EventArgs e) { OpenDat dat = ControlDat.GetDat(currentDat); string message = (LocaleRU) ? "Сохранить изменения в DAT файл?" : "Save changes to a DAT file?"; if (!dat.IsFO2Type()) { message += (LocaleRU) ? "\n\nПримечание: Данная версия программы не поддерживает сжатие добавленных файлов для DAT формата Fallout 1." : "\n\nNote: This version does not support the compression of the added files for DAT Fallout 1 format."; } if (MessageBox.Show(message, "Dat Explorer II", MessageBoxButtons.YesNo) == DialogResult.No) { return; } statusToolStripStatusLabel.Text = "Saving:"; textToolStripStatusLabel.Text = "Prepare..."; int count = dat.TotalFiles - dat.AddedFiles; if (count > 1000) { count /= 5; } count += (dat.AddedFiles > 1000) ? dat.AddedFiles / 5 : dat.AddedFiles; toolStripProgressBar.Maximum = count; if (dat.SaveDat()) { FindFiles(currentDat, folderTreeView.SelectedNode); } SaveToolStripButton.Enabled = false; toolStripProgressBar.Value = 0; textToolStripStatusLabel.Text = "Done."; }
internal void DeleteFiles(ListView.SelectedListViewItemCollection listPath) { List <String> listFiles = new List <String>(); foreach (ListViewItem item in listPath) { if (item.Tag == null) // remove folder and all files in sub folders { GetFolderFiles(listFiles, item.Name); } else { var file = (sFile)item.Tag; listFiles.Add(file.path); } } if (listFiles.Count > 0) { toolStripProgressBar.Maximum = listFiles.Count; ControlDat.GetDat(currentDat).DeleteFile(listFiles, false); } }
private void Delete(bool isList) { if (MessageBox.Show((LocaleRU) ? "Вы действительно хотите это удалить?" : "Do you want to delete it?", "Dat Explorer II", MessageBoxButtons.YesNo) == DialogResult.No) { return; } statusToolStripStatusLabel.Text = "Deleting:"; textToolStripStatusLabel.Text = "Prepare..."; if (isList) { new WaitForm(this).RemoveFile(filesListView.SelectedItems); FindFiles(currentDat, currentNode); } else { new WaitForm(this).RemoveFile(currentNode.Name); folderTreeView.Nodes.Remove(currentNode); } textToolStripStatusLabel.Text = toolStripProgressBar.Value + " file(s)"; toolStripProgressBar.Value = 0; var dat = ControlDat.GetDat(currentDat); totalToolStripStatusLabel.Text = dat.TotalFiles.ToString(); if (dat.ShouldSave()) { SaveToolStripButton.Enabled = true; } }
private void filesListView_AfterLabelEdit(object sender, LabelEditEventArgs e) { deleteFilesToolStripMenuItem.Enabled = true; filesListView.LabelEdit = false; skipKeyEvent = true; if (!createFolder && (e.Label == null || e.Label.Equals(filesListView.Items[e.Item].Text))) { e.CancelEdit = true; return; } string newName = e.Label ?? filesListView.Items[e.Item].Text; if (e.Label != null) { bool isSelfRename = e.Label.Equals(filesListView.Items[e.Item].Text, StringComparison.OrdinalIgnoreCase); if (!isSelfRename) { foreach (ListViewItem item in filesListView.Items) { if (e.Label.Equals(item.Text, StringComparison.OrdinalIgnoreCase)) { if (item.Tag == null) { MessageBox.Show((LocaleRU) ? "Директория с таким именем уже существует." : "This directory already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); if (createFolder) { newName = filesListView.Items[e.Item].Text; e.CancelEdit = true; break; } } else // file { MessageBox.Show((LocaleRU) ? "Файл с таким именем уже существует." : "The file with the same name already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); } e.CancelEdit = true; return; } } } } OpenDat dat = ControlDat.GetDat(currentDat); string fullPath = Misc.GetNodeFullPath(currentNode); if (createFolder) { string folderPath = fullPath + '\\' + newName + '\\'; folderPath = folderPath.Substring(currentDat.Length + 1); TreeNode addNode = new TreeNode(newName); addNode.Name = folderPath.ToLowerInvariant(); currentNode.Nodes.Add(addNode); filesListView.Items[e.Item].Name = addNode.Name; dat.AddEmptyFolder(folderPath); createFolder = false; } else { string pathTo = (fullPath + '\\' + filesListView.Items[e.Item].Text).ToLowerInvariant(); pathTo = pathTo.Substring(currentDat.Length + 1); if (filesListView.Items[e.Item].Tag == null) // folder { pathTo += '\\'; string renamePath = dat.RenameFolder(pathTo, e.Label); if (renamePath == null) { return; } filesListView.Items[e.Item].Name = renamePath; // rename path and name for tree node TreeNode node = Misc.FindPathNode(pathTo, currentNode); node.Name = renamePath; node.Text = e.Label; } else { filesListView.Items[e.Item].Tag = dat.RenameFile(pathTo, e.Label); } } SaveToolStripButton.Enabled = dat.ShouldSave(); }
private void OpenFile() { if (filesListView.SelectedItems.Count == 0) { return; } var item = filesListView.SelectedItems[0]; if (item.Tag != null) // open file { sFile sfile = (sFile)item.Tag; if (sfile.isVirtual) { string realfile = ControlDat.GetDat(currentDat).GetFile(sfile.path).RealFile; if (File.Exists(realfile)) { System.Diagnostics.Process.Start("explorer", realfile); } return; } var file = new string[1] { sfile.path }; if (sfile.file.info.Size > 1048576) // 1mb { new WaitForm(this).UnpackFile(tmpAppFolder, file, currentDat); } else { DATManage.ExtractFile(tmpAppFolder, sfile.path, currentDat); } string ofile = tmpAppFolder + file[0]; if (File.Exists(ofile)) { System.Diagnostics.Process.Start("explorer", ofile); } } else // folder { foreach (TreeNode node in folderTreeView.SelectedNode.Nodes) { if (node.Text == item.Text) { folderTreeView.SelectedNode = node; break; } } if (currentNode != null) { currentNode.ForeColor = Color.White; } currentNode = folderTreeView.SelectedNode; currentNode.ForeColor = Color.Yellow; FindFiles(currentDat, item.Name); upToolStripButton.Enabled = (currentNode.Parent != null); } }
private void FindFiles(string datPath, string pathFolder) { string path = pathFolder.ToLowerInvariant(); OpenDat dat = ControlDat.GetDat(datPath); List <String> subDirs = new List <String>(); int len = path.Length; foreach (var item in dat.Folders) { if (item.Key.StartsWith(path)) { string dirs = item.Value.FolderPath.TrimEnd('\\'); if (dirs.Length == 0 || len > dirs.Length) { continue; } int i = (len > 0) ? dirs.LastIndexOf('\\') : dirs.IndexOf('\\'); if (i > len) { string sub = dirs.Substring(len, i - len); if (!subDirs.Contains(sub)) { subDirs.Add(sub); } } else { subDirs.Add(dirs.Substring(len)); } } } filesListView.BeginUpdate(); filesListView.Items.Clear(); foreach (string dir in subDirs) { if (dir.Length > 0) { ListViewItem lwItem = new ListViewItem(dir, 0); lwItem.Name = path + dir.ToLowerInvariant() + "\\"; lwItem.SubItems.Add("<DIR>"); filesListView.Items.Add(lwItem); } } int dirCount = filesListView.Items.Count; // add files if (dat.Folders.ContainsKey(path)) { var datFolders = dat.Folders[path]; foreach (sFile el in datFolders.GetFiles()) { ListViewItem lwItem = new ListViewItem(el.file.name, (el.file.info.PackedSize == -1) ? 2 : 1); lwItem.Tag = el; if (filesListView.View == View.Details) { lwItem.SubItems.Add((el.file.info.IsPacked) ? "Packed" : (el.file.info.PackedSize == -1) ? "Virtual" : string.Empty); lwItem.SubItems.Add(el.file.info.Size.ToString()); lwItem.SubItems.Add((el.file.info.PackedSize != -1) ? el.file.info.PackedSize.ToString() : "N/A"); } filesListView.Items.Add(lwItem); } } filesListView.EndUpdate(); toolStripStatusLabelEmpty.Text = string.Format("{0} folder(s), {1} file(s).", dirCount, filesListView.Items.Count - dirCount); totalToolStripStatusLabel.Text = dat.TotalFiles.ToString(); dirToolStripStatusLabel.Text = "Directory: " + path; }
private void GetFolderFiles(List <String> listFiles, string folderPath) { OpenDat dat = ControlDat.GetDat(currentDat); dat.GetFilesFromFolder(listFiles, folderPath); }