Пример #1
0
        internal static void BuildTreeSub(OpenDat dat, TreeNode root)
        {
            foreach (var folder in dat.Folders)
            {
                if (folder.Key.Length > 1)
                {
                    string[] dirs = folder.Key.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); // dirs in lower case

                    TreeNode tn         = root;
                    string   parentsDir = String.Empty;

                    for (int i = 0; i < dirs.Length; i++)
                    {
                        parentsDir += dirs[i] + "\\";
                        TreeNode find = Misc.FindNode(dirs[i], tn);
                        if (find == null)
                        {
                            tn      = tn.Nodes.Add(folder.Value.FolderName(i)); // имя папки
                            tn.Name = parentsDir;                               // путь к папке (не должен содержать знак разделителя пути в начале)
                        }
                        else
                        {
                            tn = find;
                        }
                    }
                }
            }
        }
Пример #2
0
        static internal OpenDat OpeningDat(string pathDat, bool create = false)
        {
            OpenDat dat = new OpenDat(pathDat, (!create) ? DATManage.GetFiles(pathDat) : new Dictionary <string, DATLib.FileInfo>());

            OpenDat().Add(dat);
            return(dat);
        }
Пример #3
0
        static internal void CloseDat(string datName)
        {
            OpenDat dat = GetDat(datName);

            dat.CloseDat();
            openDat.Remove(dat);
        }
Пример #4
0
        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";
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }
Пример #7
0
        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;
        }
Пример #8
0
        private void ReBuildTreeNode(OpenDat dat)
        {
            List <TreeNode> expandNodes = new List <TreeNode>();

            Misc.GetExpandedNodes(currentNode, ref expandNodes);

            folderTreeView.BeginUpdate();
            currentNode.Nodes.Clear();

            if (currentNode.Parent == null)
            {
                Misc.BuildTreeSub(dat, currentNode);
            }
            else
            {
                foreach (var item in dat.Folders)
                {
                    if (item.Key.Length > currentNode.Name.Length && item.Key.StartsWith(currentNode.Name))
                    {
                        string[] dirs = item.Key.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

                        TreeNode tn         = currentNode;
                        string   parentsDir = dirs[0] + "\\";

                        for (int i = 1; i < dirs.Length; i++)
                        {
                            parentsDir += dirs[i] + "\\";

                            if (tn.Text != dirs[i])
                            {
                                TreeNode find = Misc.FindNode(dirs[i], tn);
                                if (find == null)
                                {
                                    tn      = tn.Nodes.Add(item.Value.FolderName(i)); // имя папки
                                    tn.Name = parentsDir;                             // путь к папке (не должен содержать знак разделителя пути в начале)
                                }
                                else
                                {
                                    tn = find;
                                }
                            }
                        }
                    }
                }
            }
            foreach (TreeNode node in expandNodes)
            {
                Misc.ExpandNode(node, currentNode);
            }

            currentNode.Expand();
            folderTreeView.EndUpdate();
        }
Пример #9
0
        private void BuildTree(OpenDat dat)
        {
            folderTreeView.BeginUpdate();

            TreeNode root = folderTreeView.Nodes.Add(dat.DatName, string.Format("[F{0}] ", dat.IsFO2Type() ? 2 : 1) + dat.DatName);

            root.NodeFont           = new Font(folderTreeView.Font, FontStyle.Bold);
            root.SelectedImageIndex = root.ImageIndex = 2;

            Misc.BuildTreeSub(dat, root);
            root.Expand();
            folderTreeView.EndUpdate();
        }
Пример #10
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;
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
        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;
        }
Пример #13
0
        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.";
        }
Пример #14
0
        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;
        }
Пример #15
0
        private void GetFolderFiles(List <String> listFiles, string folderPath)
        {
            OpenDat dat = ControlDat.GetDat(currentDat);

            dat.GetFilesFromFolder(listFiles, folderPath);
        }
Пример #16
0
        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();
        }