Skip to content

Commit

Permalink
Update 1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
amrshaheen61 committed Nov 11, 2023
1 parent 0486328 commit b6e4fa5
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 27 deletions.
55 changes: 43 additions & 12 deletions Core/rmdtoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public class FileInfo

public string Name;
public bool IsEdited = false;
public byte[] NewFileBytes;
public object NewFileBytes;



public void Read(IStream stream)
Expand Down Expand Up @@ -344,19 +345,40 @@ public void SetFile()
var info = CompressInfos[0];
var stream = new FStream(GetRMDBLOBPath(info), FileMode.Open, FileAccess.ReadWrite);

byte[] CompressedBytes;
byte[] CompressedBytes = null;

if (info.isCompressed != 0)
if (NewFileBytes.GetType().IsArray)
{
info.BufferUSize = NewFileBytes.Length;
CompressedBytes = LZ4Codec.Encode(NewFileBytes, 0, info.BufferUSize);
info.BufferSize = CompressedBytes.Length;
var bytes = (byte[])NewFileBytes;
if (info.isCompressed != 0)
{
info.BufferUSize = bytes.Length;
CompressedBytes = LZ4Codec.Encode(bytes, 0, info.BufferUSize);
info.BufferSize = CompressedBytes.Length;
}
else
{
info.BufferUSize = bytes.Length;
CompressedBytes = bytes;
info.BufferSize = 0;
}
}
else
else if (NewFileBytes is IStream)
{
info.BufferUSize = NewFileBytes.Length;
CompressedBytes = NewFileBytes;
info.BufferSize = 0;

var bytes = ((IStream)NewFileBytes).ToArray();
if (info.isCompressed != 0)
{
info.BufferUSize = bytes.Length;
CompressedBytes = LZ4Codec.Encode(bytes, 0, info.BufferUSize);
info.BufferSize = CompressedBytes.Length;
}
else
{
info.BufferUSize = bytes.Length;
CompressedBytes = bytes;
info.BufferSize = 0;
}
}

/////
Expand All @@ -373,7 +395,16 @@ public void SetFile()
stream.Close();

IsEdited = false;
NewFileBytes = null;


if (NewFileBytes.GetType().IsArray)
{
NewFileBytes = null;
}
else if (NewFileBytes is IStream)
{
((IStream)NewFileBytes).Close();
}
}


Expand Down Expand Up @@ -477,7 +508,7 @@ private void MakeNode(List<FolderInfo> folders, TreeNode node, FolderInfo Folder
{
for (int i = Folder.FolderIndex; i < Folder.FolderIndex + Folder.FolderCount; i++)
{
var treenode = new TreeNode(folders[i].Name);
var treenode = new TreeNode(folders[i].Name);
treenode.Tag = folders[i];
node.Nodes.Add(treenode);
MakeNode(folders, treenode, folders[i]);
Expand Down
38 changes: 35 additions & 3 deletions Forms/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 125 additions & 9 deletions Forms/FrmMain.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using alan_wake_2_rmdtoc_Tool.Forms;
using Controls;
using Helper;
using LZ4;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -54,7 +56,7 @@ private void eportSelectedToolStripMenuItem_Click(object sender, EventArgs e)
foreach (ListViewItem item in listView1.SelectedItems)
{
var fileInfo = item.Tag as FileInfo;
File.WriteAllBytes(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetFile());
SaveFile(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetFile());
}

MessageBox.Show("Done!");
Expand Down Expand Up @@ -102,7 +104,7 @@ private void expotAllToolStripMenuItem_Click(object sender, EventArgs e)
foreach (ListViewItem item in listView1.Items)
{
var fileInfo = item.Tag as FileInfo;
File.WriteAllBytes(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetFile());
SaveFile(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetFile());
}
}

Expand All @@ -111,7 +113,7 @@ private void stringTableEditorToolStripMenuItem_Click(object sender, EventArgs e
new FrmStringTable().Show();
}



private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -146,7 +148,7 @@ private void listView1_DoubleClick(object sender, EventArgs e)
try
{
fileInfo.IsEdited = true;
fileInfo.NewFileBytes = MStream.ToArray();
fileInfo.NewFileBytes = MStream;
Modifiedtrmdtoc.Add(fileInfo.Rmdtoc);
MessageBox.Show("Done!");
}
Expand Down Expand Up @@ -186,7 +188,7 @@ private void exportRowToolStripMenuItem_Click(object sender, EventArgs e)
foreach (ListViewItem item in listView1.SelectedItems)
{
var fileInfo = item.Tag as FileInfo;
File.WriteAllBytes(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetRow());
SaveFile(Path.Combine(folderDialog.FileName, fileInfo.Name), fileInfo.GetRow());
}

MessageBox.Show("Done!");
Expand All @@ -207,24 +209,138 @@ private void importfiles_Click(object sender, EventArgs e)
if (ofd.ShowDialog() != DialogResult.OK)
return;
var ImportedFiles = 0;
foreach(var FilePath in ofd.FileNames)
foreach (var FilePath in ofd.FileNames)
{
var item= listView1.Items.Cast<ListViewItem>().FirstOrDefault(x => x.Text == Path.GetFileName(FilePath));
var item = listView1.Items.Cast<ListViewItem>().FirstOrDefault(x => x.Text == Path.GetFileName(FilePath));
if (item == null)
{
MessageBox.Show($"File {Path.GetFileName(FilePath)} not found in list, the file will be ignored");
continue;
}
var fileInfo = item.Tag as FileInfo;
fileInfo.IsEdited = true;
fileInfo.NewFileBytes = File.ReadAllBytes(FilePath);
fileInfo.NewFileBytes = FStream.Open(FilePath, FileMode.Open, FileAccess.Read);
Modifiedtrmdtoc.Add(fileInfo.Rmdtoc);
ImportedFiles++;

item.Font= new System.Drawing.Font(item.Font, System.Drawing.FontStyle.Bold);
item.Font = new System.Drawing.Font(item.Font, System.Drawing.FontStyle.Bold);
}

MessageBox.Show($"Done! {ImportedFiles} files imported");
}

private void exportSelectedFolderToolStripMenuItem_Click(object sender, EventArgs e)
{

if (treeView1.SelectedNode == null)
{
MessageBox.Show("Select a folder first");
return;
}

FolderDialog folderDialog = new FolderDialog();
if (folderDialog.ShowDialog() != DialogResult.OK)
return;

var selectedNode = treeView1.SelectedNode;
var basefolder = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(folderDialog.FileName);

ExportFolder(selectedNode, Path.Combine(folderDialog.FileName, selectedNode.Text));

Directory.SetCurrentDirectory(basefolder);
MessageBox.Show("Done!");
}


void ExportFolder(TreeNode node, string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

var folderInfo = node.Tag as FolderInfo;
if (folderInfo == null)
return;

foreach (var item in folderInfo.Files)
{
SaveFile(Path.Combine(path, item.Name), item.GetFile());
}

foreach (TreeNode item in node.Nodes)
{
ExportFolder(item, Path.Combine(path, item.Text));
}


}



void ImportFolder(TreeNode node, string path,ref int ImportedFiles)
{
var folderInfo = node.Tag as FolderInfo;
if (folderInfo == null)
return;

foreach (var item in folderInfo.Files)
{

if (File.Exists(Path.Combine(path, item.Name)))
{
item.IsEdited = true;
item.NewFileBytes = FStream.Open(Path.Combine(path, item.Name),FileMode.Open,FileAccess.Read);
Modifiedtrmdtoc.Add(item.Rmdtoc);
ImportedFiles++;
}
}

foreach (TreeNode item in node.Nodes)
{
ImportFolder(item, Path.Combine(path, item.Text), ref ImportedFiles);
}
}

private void importToSelectedFolderToolStripMenuItem_Click(object sender, EventArgs e)
{


MessageBox.Show("Make sure that the files names in this folder in the folder you will select it");

if (treeView1.SelectedNode == null)
{
MessageBox.Show("Select a folder first");
return;
}

FolderDialog folderDialog = new FolderDialog();
if (folderDialog.ShowDialog() != DialogResult.OK)
return;

var ImportedFiles = 0;
var selectedNode = treeView1.SelectedNode;
var basefolder = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(folderDialog.FileName);
ImportFolder(selectedNode, Path.Combine(folderDialog.FileName, selectedNode.Text), ref ImportedFiles);
Directory.SetCurrentDirectory(basefolder);


MessageBox.Show($"Done! {ImportedFiles} files imported");
}

void SaveFile(string FilePath , byte[] bytes)
{
File.WriteAllBytes(FilePath, bytes);

}



private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
}
}
Loading

0 comments on commit b6e4fa5

Please sign in to comment.