Archive fixes for replacing folder.

This commit is contained in:
KillzXGaming 2021-12-28 15:02:38 -05:00
parent 6b14db6ffe
commit 54dce49fdd
2 changed files with 27 additions and 2 deletions

View file

@ -214,6 +214,17 @@ namespace Toolbox.Library
}
}
public static string GetFolderAbsoultePath(TreeNode node, ArchiveRootNodeWrapper rootNode)
{
string nodePath = node.FullPath;
int startIndex = nodePath.IndexOf(rootNode.Text);
if (startIndex > 0)
nodePath = nodePath.Substring(startIndex);
string slash = Path.DirectorySeparatorChar.ToString();
string slashAlt = Path.AltDirectorySeparatorChar.ToString();
return nodePath.Replace(rootNode.Text + slash, string.Empty).Replace(slash ?? "", slashAlt);
}
public static void AddFiles(TreeNode parentNode, ArchiveRootNodeWrapper rootNode, string[] Files)
{

View file

@ -137,7 +137,10 @@ namespace Toolbox.Library
if (ofd.ShowDialog() == DialogResult.OK)
{
FileData = File.ReadAllBytes(ofd.FileName);
if (FileDataStream != null)
FileDataStream = new MemoryStream(File.ReadAllBytes(ofd.FileName));
else
FileData = File.ReadAllBytes(ofd.FileName);
return true;
}
return false;
@ -782,7 +785,18 @@ namespace Toolbox.Library
Nodes.Clear();
TreeHelper.AddFiles(this, RootNode, Directory.GetFiles(ofd.SelectedPath));
var proccessedFiles = TreeHelper.ReadFiles(ofd.SelectedPath);
string folderPath = TreeHelper.GetFolderAbsoultePath(this, RootNode);
for (int i = 0; i < proccessedFiles.Count; i++)
{
ArchiveFile.AddFile(new ArchiveFileInfo()
{
FileName = $"{folderPath}/{proccessedFiles[i].Item1}",
FileData = File.ReadAllBytes(proccessedFiles[i].Item2),
});
}
RootNode.FillTreeNodes();
}
}