Skip to content

Commit

Permalink
logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgeoisDirk committed Jul 31, 2020
1 parent 1dcf631 commit 3003713
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 17 deletions.
Binary file modified .vs/PS2 ISO Helper/v16/.suo
Binary file not shown.
47 changes: 38 additions & 9 deletions Codex/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum Actions

public delegate void FileStarted(string filename);
public delegate void FileSuccess(string filename);
public delegate void FileRenamed(string oldname, string newname);
public delegate void FileFailed(string filename);
public delegate void FileStopped(string filename);

Expand All @@ -42,6 +43,7 @@ public enum Actions

public event FileStarted FileStart;
public event FileSuccess FileOK;
public event FileRenamed FileRename;
public event FileFailed FileNOK;
public event FileStopped FileStop;

Expand Down Expand Up @@ -370,24 +372,31 @@ private bool IdentifyIsoFiles()
if (string.IsNullOrEmpty(exception))
{
string newPath = Path.Combine(TargetSuccessDirectory, GetNewFilename(mapping, id, isoFile.Name));
if (File.Exists(newPath))
if (isoFile.FullName == newPath)
{
Error?.Invoke("Duplicate File");
FileNOK?.Invoke(isoFile.Name);
File.Move(isoFile.FullName, Path.Combine(TargetFailureDirectory, isoFile.Name));
FileOK?.Invoke(isoFile.Name);
}
else
{
FileOK?.Invoke(isoFile.Name);
File.Move(isoFile.FullName, newPath);
{
if (File.Exists(newPath))
{
Error?.Invoke("Duplicate File");
FileNOK?.Invoke(isoFile.Name);
MoveFailedFile(isoFile.FullName, Path.Combine(TargetFailureDirectory, isoFile.Name));
}
else
{
FileRename?.Invoke(isoFile.Name, Path.GetFileName(newPath));
FileOK?.Invoke(isoFile.Name);
File.Move(isoFile.FullName, newPath);
}
}

}
else
{
Error?.Invoke(exception);
FileNOK?.Invoke(isoFile.Name);
File.Move(isoFile.FullName, Path.Combine(TargetFailureDirectory, isoFile.Name));
MoveFailedFile(isoFile.FullName, Path.Combine(TargetFailureDirectory, isoFile.Name));
}

FileStop?.Invoke(isoFile.Name);
Expand All @@ -400,6 +409,26 @@ private bool IdentifyIsoFiles()
return true;
}

private void MoveFailedFile(string source, string target)
{
if (File.Exists(target))
{
string dir = Path.GetDirectoryName(target);
string name = Path.GetFileNameWithoutExtension(target);
string ext = Path.GetExtension(target);

int counter = 1;
while (File.Exists(Path.Combine(dir, Path.ChangeExtension(name + counter.ToString(), ext))))
counter++;

File.Move(source, Path.Combine(dir, Path.ChangeExtension(name + counter.ToString(), ext)));
}
else
{
File.Move(source, target);
}
}

private string IdentifyIso(FileInfo isoFile, out string id)
{
id = null;
Expand Down
Binary file modified Codex/bin/Debug/PS2 Codex.dll
Binary file not shown.
Binary file modified Codex/bin/Debug/PS2 Codex.pdb
Binary file not shown.
Binary file modified Codex/obj/Debug/Codex.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified Codex/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file modified Codex/obj/Debug/PS2 Codex.dll
Binary file not shown.
Binary file modified Codex/obj/Debug/PS2 Codex.pdb
Binary file not shown.
12 changes: 6 additions & 6 deletions GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PS2_Image_Reader"
mc:Ignorable="d"
Title="PS2 ISO Helper" Height="597.039" Width="811">
Title="PS2 ISO Helper" Height="585.832" Width="802.849">
<Grid>
<TextBox x:Name="SourceDirectory_Textbox" Height="23" Margin="228,11,21,0" TextWrapping="Wrap" VerticalAlignment="Top" LostFocus="SourceDirectory_Textbox_LostFocus"/>
<Button x:Name="Go_Button" Content="Go" Margin="707,81,21,0" VerticalAlignment="Top" Click="Go_Button_Click"/>
<TextBox x:Name="SourceDirectory_Textbox" Height="23" Margin="228,11,13,0" TextWrapping="Wrap" VerticalAlignment="Top" LostFocus="SourceDirectory_Textbox_LostFocus"/>
<Button x:Name="Go_Button" Content="Go" Margin="707,81,13,0" VerticalAlignment="Top" Click="Go_Button_Click"/>
<Label Content="Source Files Directory" HorizontalAlignment="Left" Margin="10,7,0,0" VerticalAlignment="Top" Width="213"/>
<TextBox x:Name="TargetBadISO_Textbox" Height="23" Margin="228,46,21,0" TextWrapping="Wrap" VerticalAlignment="Top" IsEnabled="False"/>
<TextBox x:Name="TargetBadISO_Textbox" Height="23" Margin="228,46,13,0" TextWrapping="Wrap" VerticalAlignment="Top" IsEnabled="False"/>
<Label Content="Failed Files Directory" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Width="213"/>
<CheckBox x:Name="OPLFriendly_CheckBox" Content="Make filename OPL Friendly" HorizontalAlignment="Left" Margin="13,82,0,0" VerticalAlignment="Top" IsChecked="True" Checked="OPLFriendly_CheckBox_Checked" Unchecked="OPLFriendly_CheckBox_Unchecked"/>
<CheckBox x:Name="LimitCharacters_CheckBox" Content="Limit Characters to &quot; abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_()[]&quot;" HorizontalAlignment="Left" Margin="34,102,0,0" VerticalAlignment="Top" IsChecked="True"/>
<CheckBox x:Name="RemoveBracketContent_CheckBox" Content="Remove Brackets &quot;(&quot; and &quot;)&quot; with Content" HorizontalAlignment="Left" Margin="34,117,0,0" VerticalAlignment="Top" IsChecked="True"/>
<CheckBox x:Name="ShortenTo32Characters_CheckBox" Content="Shorten the Game Name to 32 Characters" HorizontalAlignment="Left" Margin="34,132,0,0" VerticalAlignment="Top" IsChecked="True"/>

<TextBlock x:Name="Status_TextBlock" HorizontalAlignment="Left" Margin="10,183,0,0" TextWrapping="Wrap" Text="Status" VerticalAlignment="Top" Width="208" Height="20" FontSize="10"/>
<ProgressBar x:Name="StatusBar" Height="20" Margin="223,183,21,0" VerticalAlignment="Top" />
<TextBox x:Name="Output_Textbox" Margin="10,208,21,23" TextWrapping="NoWrap" IsReadOnly="True"/>
<ProgressBar x:Name="StatusBar" Height="20" Margin="223,183,13,0" VerticalAlignment="Top" />
<TextBox x:Name="Output_Textbox" Margin="10,208,13,11" TextWrapping="NoWrap" IsReadOnly="True"/>
</Grid>
</Window>
24 changes: 22 additions & 2 deletions GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.IO;
using System.Threading;
using System.Windows;

namespace PS2_Image_Reader
{
public partial class MainWindow : Window
{
private string LogFilePath => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "Log.txt");

public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -56,14 +59,17 @@ private void Beta()
{
Thread.CurrentThread.IsBackground = true;

File.Create(LogFilePath);

var identifier = new PS2_Codex.Identifier();
identifier.Error += Identifier_Error;
identifier.Update += Identifier_Update;
identifier.ActionStart += Identifier_ActionStart;
identifier.ActionStop += Identifier_ActionStop;
identifier.FileStart += Identifier_FileStart;
identifier.FileOK += Identifier_FileOK;
identifier.FileNOK += Identifier_FileNOK;
identifier.FileRename += Identifier_FileRename;

if (opl)
{
Expand All @@ -75,7 +81,17 @@ private void Beta()
identifier.Initialize(source, targetNOK, targetOK, true);
identifier.Execute();

}).Start();
}).Start();
}

private void Identifier_FileRename(string oldname, string newname)
{
AddOutput(string.Format("File Renamed from '{0}' to '{1}'", oldname, newname));
}

private void Identifier_FileStart(string filename)
{
AddOutput("File Started: " + filename);
}

private void Identifier_FileNOK(string filename)
Expand Down Expand Up @@ -126,8 +142,12 @@ private void Identifier_Error(string exception)

private void AddOutput(string line)
{
string output = DateTime.Now.ToString("HH:mm:ss") + " " + line;

File.AppendAllText(LogFilePath, Environment.NewLine + output);

this.Dispatcher.Invoke(() => {
Output_Textbox.Text = DateTime.Now.ToString("HH:mm:ss") + " " + line + Environment.NewLine + Output_Textbox.Text;
Output_Textbox.Text = output + Environment.NewLine + Output_Textbox.Text;
});
}

Expand Down
Binary file modified GUI/bin/Debug/PS2 Codex.dll
Binary file not shown.
Binary file modified GUI/bin/Debug/PS2 Codex.pdb
Binary file not shown.
Binary file modified GUI/bin/Debug/PS2 Image Reader.exe
Binary file not shown.
Binary file modified GUI/bin/Debug/PS2 Image Reader.pdb
Binary file not shown.
Binary file modified GUI/obj/Debug/GUI.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified GUI/obj/Debug/PS2 Image Reader.exe
Binary file not shown.
Binary file modified GUI/obj/Debug/PS2 Image Reader.pdb
Binary file not shown.

0 comments on commit 3003713

Please sign in to comment.