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,16 +2383,24 @@ namespace CodeWalker
{
return;//no name was provided.
}
if (!IsFilenameOk(fname)) return; //new name contains invalid char(s). don't do anything
string cpath = (string.IsNullOrEmpty(CurrentFolder.Path) ? "" : CurrentFolder.Path + "\\");
string relpath = cpath + fname.ToLowerInvariant();
var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash();
string fullpath = rootpath + relpath;
var fnames = fname.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
RpfDirectoryEntry newdir = null;
MainTreeFolder node = null;
MainTreeFolder cnode = null;
string cpath = (string.IsNullOrEmpty(CurrentFolder.Path) ? "" : CurrentFolder.Path + "\\");
var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash();
var csubpath = "";
foreach (var name in fnames)
{
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
{
@ -2402,9 +2410,20 @@ namespace CodeWalker
//create new directory entry in the RPF.
newdir = RpfFile.CreateDirectory(CurrentFolder.RpfFolder, fname);
newdir = RpfFile.CreateDirectory(newdir ?? CurrentFolder.RpfFolder, name);
node = CreateRpfDirTreeFolder(newdir, relpath, fullpath);
var newnode = CreateRpfDirTreeFolder(newdir, relpath, fullpath);
if (node == null)
{
node = newnode;
cnode = newnode;
}
else
{
cnode.AddChild(newnode);
cnode = newnode;
}
}
else
{
@ -2415,7 +2434,17 @@ namespace CodeWalker
}
Directory.CreateDirectory(fullpath);
node = CreateRootDirTreeFolder(fname, relpath, fullpath);
var newnode = CreateRootDirTreeFolder(name, relpath, fullpath);
if (node == null)
{
node = newnode;
cnode = newnode;
}
else
{
cnode.AddChild(newnode);
cnode = newnode;
}
}
}
catch (Exception ex)
@ -2424,6 +2453,10 @@ namespace CodeWalker
return;
}
csubpath += "\\";
}
if (node != null)
{
AddNewFolderTreeNode(node);