Skip to content

Commit

Permalink
[HaRepacker] Multi load wzs in a folder.
Browse files Browse the repository at this point in the history
TODO: load the parts as 1 wz.
  • Loading branch information
lastbattle committed Oct 4, 2021
1 parent 1f29e49 commit 7fe44c8
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 225 deletions.
25 changes: 18 additions & 7 deletions HaRepacker/GUI/MainForm.Designer.cs

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

85 changes: 84 additions & 1 deletion HaRepacker/GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ private void tabControl_MainPanels_KeyUp(object sender, KeyEventArgs e)
case Keys.O: // Open new WZ file
openToolStripMenuItem_Click(null, null);
break;
case Keys.I: // Open new Wz format
toolStripMenuItem_newWzFormat_Click(null, null);
break;
case Keys.N: // New
newToolStripMenuItem_Click(null, null);
break;
Expand Down Expand Up @@ -714,7 +717,7 @@ private void WzKeyBruteforceComputeTask(int cpuId_, int processorCount, OpenFile

#region Toolstrip Menu items
/// <summary>
/// Open file
/// Open WZ file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Expand Down Expand Up @@ -855,6 +858,86 @@ await Task.Run(() =>
}
}

/// <summary>
/// Open new WZ file (KMST)
/// with the split format
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void toolStripMenuItem_newWzFormat_Click(object sender, EventArgs e)
{
Dispatcher currentDispatcher = Dispatcher.CurrentDispatcher;

WzMapleVersion MapleVersionEncryptionSelected = GetWzMapleVersionByWzEncryptionBoxSelection(encryptionBox.SelectedIndex);

// Load WZ file
using (FolderBrowserDialog fbd = new FolderBrowserDialog()
{
Description = "Select the WZ folder (Base, Mob, Character, etc)",
ShowNewFolderButton = true,
})
{
DialogResult result = fbd.ShowDialog();
if (result != DialogResult.OK || string.IsNullOrWhiteSpace(fbd.SelectedPath))
return;

string[] iniFilesPath = Directory.GetFiles(fbd.SelectedPath, "*.ini", SearchOption.AllDirectories);

// Search for all '.ini' file, and for each .ini found, proceed to parse all items in the sub directory
// merge all parsed directory as a single WZ

List<string> wzfilePathsToLoad = new List<string>();
foreach (string iniFilePath in iniFilesPath)
{
string directoryName = Path.GetDirectoryName(iniFilePath);
string[] wzFilesPath = Directory.GetFiles(directoryName, "*.wz", SearchOption.TopDirectoryOnly);

foreach (string wzFilePath in wzFilesPath)
{
wzfilePathsToLoad.Add(wzFilePath);
Debug.WriteLine(wzFilePath);
}
}

// Show splash screen
MainPanel.OnSetPanelLoading();


// Load all original WZ files
await Task.Run(() =>
{
List<WzFile> loadedWzFiles = new List<WzFile>();
ParallelLoopResult loop = Parallel.ForEach(wzfilePathsToLoad, filePath =>
{
WzFile f = Program.WzFileManager.LoadWzFile(filePath, MapleVersionEncryptionSelected);
if (f == null)
{
// error should be thrown
}
else
{
lock (loadedWzFiles)
{
loadedWzFiles.Add(f);
}
}
});
while (!loop.IsCompleted)
{
Thread.Sleep(100); //?
}
foreach (WzFile wzFile in loadedWzFiles) // add later, once everything is loaded to memory
{
Program.WzFileManager.AddLoadedWzFileToMainPanel(wzFile, MainPanel, currentDispatcher);
}
}); // load complete

// Hide panel splash sdcreen
MainPanel.OnSetPanelLoadingCompleted();
}
}

private void unloadAllToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Warning.Warn(HaRepacker.Properties.Resources.MainUnloadAll))
Expand Down
Loading

0 comments on commit 7fe44c8

Please sign in to comment.