Ejemplo n.º 1
0
        protected void ExportDirectoryRecursive(BF.Directory xDir, string targetPath)
        {
            //string realTargetPath = ReplaceInvalidPathCharacters(targetPath, false);
            string realTargetPath = targetPath;

            if (!(System.IO.Directory.Exists(realTargetPath)))
            {
                System.IO.Directory.CreateDirectory(realTargetPath);
            }
            if (xDir.Directories.Count > 0)
            {
                foreach (BF.Directory subDir in xDir.Directories)
                {
                    string subDirName = ReplaceInvalidPathCharacters(subDir.Name, true);
                    ExportDirectoryRecursive(subDir, Path.Combine(targetPath, subDirName));
                }
            }

            if (xDir.Files.Count > 0)
            {
                foreach (BF.File currentFile in xDir.Files)
                {
                    string currentFileName = ReplaceInvalidPathCharacters(currentFile.Name + "." + currentFile.FileExtension, true);
                    currentFile.Export(Path.Combine(targetPath, currentFileName));
                    mCurrentFile++;
                }
            }
        }
        public BF.Directory BuildDirectoryFromRawIndex()
        {
            BF.Directory returnDir = new BF.Directory();
            returnDir.Name          = mName;
            returnDir.ParentBigFile = mParentBigFile;

            if ((mIndices != null) && (mIndices.GetUpperBound(0) > 0))
            {
                foreach (BF.Index nextIndex in mIndices)
                {
                    returnDir.Directories.Add(nextIndex.BuildDirectoryFromRawIndex());
                }
            }

            if ((mFiles != null) && (mFiles.GetUpperBound(0) > 0))
            {
                foreach (BF.File currentFile in mFiles)
                {
                    //if (returnDir.Filenames.Contains(currentFile.Name + "." + currentFile.FileExtension))
                    //{
                    //    currentFile.Name = GetNextUnusedName(returnDir.Filenames, currentFile);
                    //}
                    returnDir.AddFile(currentFile);
                }
            }

            return(returnDir);
        }
        public TreeNode getIndexNodes(BF.Directory currentDir, string currentPath)
        {
            TreeNode returnNode = new TreeNode(currentDir.Name);

            mTVLookupTable.Add(currentPath, currentDir);

            if ((currentDir.Directories != null) && (currentDir.Directories.Count > 0))
            {
                foreach (BF.Directory nextDir in currentDir.Directories)
                {
                    returnNode.Nodes.Add(getIndexNodes(nextDir, currentPath + nextDir.Name + "\\"));
                }
            }

            if ((currentDir.Files != null) && (currentDir.Files.Count > 0))
            {
                foreach (BF.File currentFile in currentDir.Files)
                {
                    returnNode.Nodes.Add(currentFile.Name + "." + currentFile.FileExtension);
                    mTVLookupTable.Add(currentPath + currentFile.Name + "." + currentFile.FileExtension, currentFile);
                }
            }

            return(returnNode);
        }
        protected int CheckFilesRecursive(BF.Directory xDir)
        {
            int retCount = 0;

            if (xDir.Directories.Count > 0)
            {
                foreach (BF.Directory subDir in xDir.Directories)
                {
                    retCount += CheckFilesRecursive(subDir);
                }
            }

            if (xDir.Files.Count > 0)
            {
                foreach (BF.File currentFile in xDir.Files)
                {
                    if (!currentFile.IsValidReference)
                    {
                        retCount++;
                    }
                }
            }

            return(retCount);
        }
Ejemplo n.º 5
0
 //for sorting
 public int CompareTo(object compObj)
 {
     if (!(compObj is BF.Directory))
     {
         throw new InvalidCastException("Can't compare BigFile Directory class with other classes.");
     }
     BF.Directory compDir = (BF.Directory)compObj;
     return(this.Name.CompareTo(compDir.Name));
 }
        protected string GetSelectedItemInfo(TreeView tv)
        {
            string fullPath  = tv.SelectedNode.FullPath;
            int    padLength = tv.Nodes[0].FullPath.Length;

            fullPath = fullPath.Substring(padLength);

            //return nothing if nothing is selected
            if (tv.SelectedNode == null)
            {
                //MessageBox.Show("No item is currently selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DisableExportCurrent();
                DisableExportDirectory();
                DisableReplace();
                DisableHexEdit();
                return(null);
            }
            if ((mTVLookupTable != null) && (fullPath.Trim() != "") && (mTVLookupTable.Contains(fullPath)) && (tv.SelectedNode.GetNodeCount(false) == 0))
            {
                //a file is selected
                BF.File selectedFile = (BF.File)mTVLookupTable[fullPath];
                EnableExportCurrent();
                DisableExportDirectory();
                if ((selectedFile != null) && (selectedFile.CanBeReplaced))
                {
                    EnableReplace();
                    EnableHexEdit();
                }
                else
                {
                    DisableReplace();
                    DisableHexEdit();
                }
                return(selectedFile.GetInfo());
            }
            else
            {
                //a node is selected, so either return information about the entire bigfile or the currently-selected
                //directory
                DisableExportCurrent();
                EnableExportDirectory();
                DisableReplace();
                DisableHexEdit();
                if (fullPath.Contains("\\"))
                {
                    BF.Directory selectedDir = (BF.Directory)mTVLookupTable[fullPath + "\\"];
                    return(selectedDir.GetInfo());
                }
                else
                {
                    return(mBigFile.GetInfo());
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
 public Directory()
 {
     mName               = "New Directory";
     mParentBigFile      = null;
     mParentDirectory    = null;
     mDirectories        = new ArrayList();
     mFiles              = new ArrayList();
     mFilenames          = new Hashtable();
     mDirectoryNames     = new Hashtable();
     mFileCountRecursive = 0;
 }
 public void BuildMasterDirectory()
 {
     if (mDirectoryMode == DirectoryModes.Normal)
     {
         mMasterDirectory = mMasterIndex.BuildDirectoryFromFileData();
         mMasterDirectory.SortAll();
     }
     else
     {
         mMasterDirectory = mMasterIndex.BuildDirectoryFromRawIndex();
         mMasterDirectory.SortAll();
     }
 }
 protected void ExportCurrentDirectory()
 {
     BF.Directory currentDir = GetCurrentDirectory(tvBigfile);
     if (currentDir == null)
     {
         MessageBox.Show("No directory is currently selected.",
                         "Export Error",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         return;
     }
     else
     {
         ExportDirectoryConfirm(currentDir);
     }
 }
        public BF.Directory BuildDirectoryFromFileData()
        {
            BF.Directory returnDir = new Directory();
            returnDir.Name = "BigFile";

            //get all sub-files, recursively
            ArrayList allFiles = new ArrayList();

            mFileCount = 0;
            allFiles   = GetAllFilesRecursively(allFiles);
            mFileCount = allFiles.Count;

            //figure out where to put the file
            foreach (BF.File currentFile in allFiles)
            {
                BF.Directory targetDir = returnDir;
                string[]     dirSplit  = currentFile.DirectoryName.Split('\\');
                //recursively get a pointer to the target directory
                for (int i = 0; i < dirSplit.GetUpperBound(0); i++)
                {
                    //create subdirectory if necessary
                    if (!(targetDir.DirectoryNames.Contains(dirSplit[i])))
                    {
                        BF.Directory newDir = new BF.Directory();
                        newDir.Name = dirSplit[i];
                        targetDir.AddDirectory(newDir);
                    }
                    targetDir = (BF.Directory)(targetDir.Directories[(int)(targetDir.DirectoryNames[dirSplit[i]])]);
                }

                //add the file
                //if (targetDir.Filenames.Contains(currentFile.Name + "." + currentFile.FileExtension))
                //{
                //    currentFile.Name = GetNextUnusedName(targetDir.Filenames, currentFile);
                //}
                targetDir.AddFile(currentFile);
            }



            return(returnDir);
        }
        protected void ExportDirectoryConfirm(BF.Directory exportDir)
        {
            string tPath;
            FolderBrowserDialog fDialogue;
            DialogResult        result1, result2;

            fDialogue = new FolderBrowserDialog();
            fDialogue.ShowNewFolderButton = true;
            result1 = fDialogue.ShowDialog();

            if (result1 == DialogResult.OK)
            {
                tPath   = fDialogue.SelectedPath;
                result2 = MessageBox.Show("Any files in the selected folder with names identical to those being exported will be overwritten.\n" +
                                          "Are you sure you want to proceed?", "Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result2 == DialogResult.Yes)
                {
                    mExporter = new DirectoryExporter(exportDir, tPath);
                    Thread xThread = new Thread(new ThreadStart(ExportDirectory));
                    xThread.Start();
                }
            }
        }
Ejemplo n.º 12
0
 public void AddDirectory(BF.Directory whichDir)
 {
     mDirectories.Add(whichDir);
     mDirectoryNames.Add(whichDir.Name, mDirectories.Count - 1);
     mFileCountRecursive += whichDir.FileCountRecursive;
 }
Ejemplo n.º 13
0
 public DirectoryExporter(BF.Directory sourceDir, string targetPath)
 {
     mSourceDirectory = sourceDir;
     mTargetPath      = targetPath;
     mTotalFiles      = mSourceDirectory.FileCountRecursive;
 }