Recursive create folders in RPF explorer

This commit is contained in:
dexy 2022-01-18 17:17:08 +11:00
parent 88016633da
commit 8f6ac6aad6

View File

@ -2383,46 +2383,79 @@ namespace CodeWalker
{ {
return;//no name was provided. return;//no name was provided.
} }
if (!IsFilenameOk(fname)) return; //new name contains invalid char(s). don't do anything
var fnames = fname.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
string cpath = (string.IsNullOrEmpty(CurrentFolder.Path) ? "" : CurrentFolder.Path + "\\");
string relpath = cpath + fname.ToLowerInvariant();
var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash();
string fullpath = rootpath + relpath;
RpfDirectoryEntry newdir = null; RpfDirectoryEntry newdir = null;
MainTreeFolder node = null; MainTreeFolder node = null;
MainTreeFolder cnode = null;
string cpath = (string.IsNullOrEmpty(CurrentFolder.Path) ? "" : CurrentFolder.Path + "\\");
var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash();
var csubpath = "";
try foreach (var name in fnames)
{ {
if (CurrentFolder.RpfFolder != null) if (!IsFilenameOk(name)) break; //new name contains invalid char(s). don't continue
csubpath += name;
string relpath = cpath + csubpath.ToLowerInvariant();
string fullpath = rootpath + relpath;
try
{ {
if (!EnsureRpfValidEncryption()) return; if (CurrentFolder.RpfFolder != null)
//create new directory entry in the RPF.
newdir = RpfFile.CreateDirectory(CurrentFolder.RpfFolder, fname);
node = CreateRpfDirTreeFolder(newdir, relpath, fullpath);
}
else
{
//create a folder in the filesystem.
if (Directory.Exists(fullpath))
{ {
throw new Exception("Folder " + fullpath + " already exists!"); if (!EnsureRpfValidEncryption()) return;
}
Directory.CreateDirectory(fullpath);
node = CreateRootDirTreeFolder(fname, relpath, fullpath); //create new directory entry in the RPF.
newdir = RpfFile.CreateDirectory(newdir ?? CurrentFolder.RpfFolder, name);
var newnode = CreateRpfDirTreeFolder(newdir, relpath, fullpath);
if (node == null)
{
node = newnode;
cnode = newnode;
}
else
{
cnode.AddChild(newnode);
cnode = newnode;
}
}
else
{
//create a folder in the filesystem.
if (Directory.Exists(fullpath))
{
throw new Exception("Folder " + fullpath + " already exists!");
}
Directory.CreateDirectory(fullpath);
var newnode = CreateRootDirTreeFolder(name, relpath, fullpath);
if (node == null)
{
node = newnode;
cnode = newnode;
}
else
{
cnode.AddChild(newnode);
cnode = newnode;
}
}
} }
catch (Exception ex)
{
MessageBox.Show("Error creating new folder: " + ex.Message, "Unable to create new folder");
return;
}
csubpath += "\\";
} }
catch (Exception ex)
{
MessageBox.Show("Error creating new folder: " + ex.Message, "Unable to create new folder");
return;
}
if (node != null) if (node != null)
{ {