Skip to content

Commit

Permalink
implement test button, build in input validation to ExCommand()
Browse files Browse the repository at this point in the history
  • Loading branch information
Blu3wolf committed Dec 3, 2017
1 parent 5913a1e commit 5ce5fb7
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 89 deletions.
15 changes: 8 additions & 7 deletions 3DDBBuilderGUI/MainWindow.xaml
Expand Up @@ -38,8 +38,8 @@
</DockPanel>
<DockPanel LastChildFill="False">
<Button Content="Extract" DockPanel.Dock="Right" Click="ExtrButton_Click" Margin="10" Style="{StaticResource WFButton}"/>
<Button Content="Open Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="OpenDirButton_Click"/>
<Button Content="Reset Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="ResetDirButton_Click"/>
<Button Content="Open Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="OpenExtractionDirButton_Click"/>
<Button Content="Reset Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="ResetExtractionDirButton_Click"/>
</DockPanel>

</StackPanel>
Expand Down Expand Up @@ -93,13 +93,13 @@
</DockPanel>
<Label Content="Select folder to Update database from:"/>
<DockPanel>
<Button Content="Select..." Style="{StaticResource WFButton}" DockPanel.Dock="Right"/>
<TextBox TextWrapping="Wrap" Text="{Binding Mode=TwoWay, Path=CurExtractionPath}" />
<Button Content="Select..." Style="{StaticResource WFButton}" DockPanel.Dock="Right" Click="SelCurUpdatePathButton_Click"/>
<TextBox TextWrapping="Wrap" Text="{Binding Mode=TwoWay, Path=CurUpdatePath}" />
</DockPanel>
<DockPanel LastChildFill="False">
<Button Content="Update" DockPanel.Dock="Right" Margin="10" Style="{StaticResource WFButton}"/>
<Button Content="Open Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" />
<Button Content="Reset Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" />
<Button Content="Update" DockPanel.Dock="Right" Margin="10" Style="{StaticResource WFButton}" Click="UpdateButton_Click"/>
<Button Content="Open Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="OpenCurUpdatePathButton_Click" />
<Button Content="Reset Directory" DockPanel.Dock="Left" Margin="10" Style="{StaticResource WFButton}" Click="ResetCurUpdatePathButton_Click" />
</DockPanel>
</StackPanel>
</Grid>
Expand All @@ -112,6 +112,7 @@
<Button Content="Select..." Click="SourceSelectButton_Click" Style="{StaticResource WFButton}"/>
<ComboBox ItemsSource="{Binding DBsList}" DisplayMemberPath="DirPath" SelectedItem="{Binding SelectedDB, Mode=TwoWay}" Margin="0,0,10,0"/>
</DockPanel>
<Button Content="Test DB" Margin="10" Style="{StaticResource WFButton}" Click="TestButton_Click"/>
</StackPanel>
</Grid>
</TabItem>
Expand Down
212 changes: 130 additions & 82 deletions 3DDBBuilderGUI/MainWindow.xaml.cs
Expand Up @@ -125,6 +125,21 @@ public string CurExtractionPath
}
}

private string updatePath;

public string CurUpdatePath
{
get => updatePath;
set
{
if (value != updatePath)
{
updatePath = value;
NotifyPropertyChanged("CurUpdatePath");
}
}
}

private string buildSource;

public string BuildSource
Expand Down Expand Up @@ -278,55 +293,37 @@ private void DestSelectButton_Click(object sender, RoutedEventArgs e)

private void ExtrButton_Click(object sender, RoutedEventArgs e)
{
if (SelectedDB.IsValid() && Directory.Exists(CurExtractionPath))
{
BuildSource = CurExtractionPath;
ExCommand(DestParams.Extract, SelectedDB.DirPath, CurExtractionPath);
}
else
{
if (Directory.Exists(CurExtractionPath))
{
MessageBox.Show("The DB could not be found at " + SelectedDB.DirPath, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
if (CurExtractionPath == null)
{
MessageBox.Show("Please select an extraction path first.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
MessageBox.Show("The destination could not be located at " + SelectedDB.DirPath, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}
ExCommand(true, SelectedDB, CurExtractionPath);
BuildSource = CurExtractionPath;
}

private void ListParents(object sender, RoutedEventArgs e)
{
if (SelectedDB.IsValid())
{
string command = @"/objectdir " + "\"" + SelectedDB.DirPath + "\"" + @" /parents";
ExCommand(command);
statuslabel.Content = "Success!";
// then figure out what to do with the newly generated UnusedParents.txt file which currently just chills in the debug dir
Process.Start("UnusedParents.txt");
}
else
ExCommand(false, SelectedDB);
}

private void BuildNewButton_Click(object sender, RoutedEventArgs e)
{
string Message = "The output of this function is a database which is incompatible with all legacy tools, including LOD Editor. Do you wish to continue?";
if (MessageBox.Show(Message, "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
{
MessageBox.Show("The DB could not be found at " + SelectedDB.DirPath, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
BuildCommand(true, BuildSource, BuildOutput);
}
}

enum DestParams
private void BuildOldButton_Click(object sender, RoutedEventArgs e)
{
BuildCommand(false, BuildSource, BuildOutput);
}

private void UpdateButton_Click(object sender, RoutedEventArgs e)
{
Extract, Build, Build_Old, Update
ExCommand(false, SelectedDB, CurUpdatePath);
}

enum SourceParams
private void TestButton_Click(object sender, RoutedEventArgs e)
{
List, Test
ExCommand(true, SelectedDB);
}

private void ExCommand(string args)
Expand All @@ -350,78 +347,102 @@ private void ExCommand(string args)
throw;
}
}

statuslabel.Content = "Success!";
}

private void ExCommand(SourceParams parameter, string dbdir)
private void ExCommand(bool IsTest, ObjDB DB)
{
if (!DB.IsValid())
{
MessageBox.Show("The DB could not be found at " + DB.DirPath, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
string args;
switch (parameter)
if (IsTest)
{
case SourceParams.List:
args = @"/objectdir " + "\"" + dbdir + "\"" + @" /parents";
break;
case SourceParams.Test:
args = @"/objectdir " + "\"" + dbdir + "\"" + @" /test";
break;
default:
return;
args = @"/objectdir " + "\"" + DB.DirPath + "\"" + @" /test";
ExCommand(args);

// then figure out what to do with the test results which chill in the output file
Process.Start("HeaderChecker.txt");
}
else
{
args = @"/objectdir " + "\"" + DB.DirPath + "\"" + @" /parents";
ExCommand(args);

// then figure out what to do with the newly generated UnusedParents.txt file which currently just chills in the debug dir
Process.Start("UnusedParents.txt");
}
ExCommand(args);
}

private void ExCommand(DestParams parameter, string source, string dest)
private void BuildCommand(bool IsNew, string source, string dest)
{
string args;
switch (parameter)
// check for existence of 256 color BMP file!

string command;
if (IsNew)
{
case DestParams.Extract:
args = @"/objectdir " + "\"" + source + "\"" + @" /extract " + "\"" + dest + "\"";
break;
case DestParams.Build:
args = @"/objectdir " + "\"" + dest + "\"" + @" /build " + "\"" + source + "\"";
break;
case DestParams.Build_Old:
args = @"/objectdir " + "\"" + dest + "\"" + @" /build_old " + "\"" + source + "\"";
break;
case DestParams.Update:
args = @"/objectdir " + "\"" + dest + "\"" + @" /update " + "\"" + source + "\"";
break;
default:
return;
command = "/build";
}
else
{
command = "/build_old";
}
if (Directory.Exists(source) && Directory.Exists(dest))
{
string args = @"/objectdir " + "\"" + dest + "\" " + command + " \"" + source + "\"";
ExCommand(args);
}
ExCommand(args);
}

private void ResetDirButton_Click(object sender, RoutedEventArgs e)
private void ExCommand(bool IsExtract, ObjDB DB, string ExtractedFolders)
{
try
if (!DB.IsValid())
{
CurExtractionPath = Directory.GetCurrentDirectory();
MessageBox.Show("The selected database could not be found at " + DB.DirPath, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
catch (Exception)
if (!(Directory.Exists(ExtractedFolders) && ExtractedFolders != null))
{

throw;
MessageBox.Show("Could not find the specified path: " + ExtractedFolders, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (ExtractedFolders == null)
{
MessageBox.Show("Please select an extraction path first.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
}

private void OpenDirButton_Click(object sender, RoutedEventArgs e)
{
OpenFolder(CurExtractionPath);
if (IsExtract)
{
string args = @"/objectdir " + "\"" + DB.DirPath + "\"" + @" /extract " + "\"" + ExtractedFolders + "\"";
ExCommand(args);
}
else
{
string args = @"/objectdir " + "\"" + DB.DirPath + "\"" + @" /update " + "\"" + ExtractedFolders + "\"";
ExCommand(args);
}
}

private void BuildNewButton_Click(object sender, RoutedEventArgs e)
private void ResetExtractionDirButton_Click(object sender, RoutedEventArgs e)
{
string Message = "The output of this function is a database which is incompatible with all legacy tools, including LOD Editor. Do you wish to continue?";
if (MessageBox.Show(Message, "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
try
{
ExCommand(DestParams.Build, BuildSource, BuildOutput);
CurExtractionPath = Directory.GetCurrentDirectory();
}
catch (Exception)
{

throw;
}
}

private void BuildOldButton_Click(object sender, RoutedEventArgs e)
private void OpenExtractionDirButton_Click(object sender, RoutedEventArgs e)
{
ExCommand(DestParams.Build_Old, BuildSource, BuildOutput);
OpenFolder(CurExtractionPath);
}

private void BuildSourceSelectButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -452,6 +473,33 @@ private void OpenBuildOutputDirectoryButton_Click(object sender, RoutedEventArgs
{
OpenFolder(BuildOutput);
}

private void SelCurUpdatePathButton_Click(object sender, RoutedEventArgs e)
{
string dir = GetFolder(false, true, "Select Updates folder", CurUpdatePath);
if (dir != null)
{
CurUpdatePath = dir;
}
}

private void OpenCurUpdatePathButton_Click(object sender, RoutedEventArgs e)
{
OpenFolder(CurUpdatePath);
}

private void ResetCurUpdatePathButton_Click(object sender, RoutedEventArgs e)
{
try
{
CurUpdatePath = Directory.GetCurrentDirectory();
}
catch (Exception)
{

throw;
}
}
}

public class ObjDB
Expand Down

0 comments on commit 5ce5fb7

Please sign in to comment.