Skip to content

Commit 1405e29

Browse files
authored
Merge pull request #2 from ShardTheBroken/0.2/multislot
Version 0.2.0
2 parents 50274a4 + aa2a2fb commit 1405e29

12 files changed

+195
-47
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
*/obj
2-
*/bin
1+
*\obj
2+
*\bin

.vs/SCVITool/v15/.suo

7.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

SCVITool.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Reference Include="System.Xml" />
5252
</ItemGroup>
5353
<ItemGroup>
54+
<Compile Include="Source\Constants.cs" />
5455
<Compile Include="Source\MainForm.cs">
5556
<SubType>Form</SubType>
5657
</Compile>

Source/Constants.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Constants.cs //
2+
3+
using System;
4+
using System.IO;
5+
using System.Reflection;
6+
7+
namespace SCVITool
8+
{
9+
public static class Constants
10+
{
11+
public static readonly string AppDataPath = Path.Combine( Environment.GetFolderPath(
12+
Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.None ), "SoulcaliburVI" );
13+
public static readonly string SavedPath = Path.Combine( AppDataPath, "Saved" );
14+
15+
public static readonly string ExecutablePath = GetExecutablePath();
16+
public static readonly string BackupPath = Path.Combine( ExecutablePath, "Backups" );
17+
18+
static string GetExecutablePath()
19+
{
20+
string path = Path.GetDirectoryName( Assembly.GetExecutingAssembly().CodeBase );
21+
22+
try
23+
{
24+
string s5 = path.Substring( 0, 5 ).ToLower();
25+
string s6 = path.Substring( 0, 6 ).ToLower();
26+
string s8 = path.Substring( 0, 8 ).ToLower();
27+
string s10 = path.Substring( 0, 10 ).ToLower();
28+
29+
if( s5 == "dir:/" || s5 == "dir:\\" )
30+
path = path.Substring( 5 );
31+
else if( s6 == "file:/" || s6 == "file:\\" || s6 == "path:/" || s6 == "path:\\" )
32+
path = path.Substring( 6 );
33+
else if( s8 == "folder:/" || s8 == "folder:\\" )
34+
path = path.Substring( 8 );
35+
else if( s10 == "directory:/" || s10 == "directory:\\" )
36+
path = path.Substring( 10 );
37+
}
38+
catch( Exception e )
39+
{
40+
Console.WriteLine( e.Message );
41+
}
42+
43+
return path;
44+
}
45+
}
46+
}

Source/MainForm.Designer.cs

+42-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/MainForm.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// MainForm.cs //
22

33
using System;
4-
using System.IO;
54
using System.Windows.Forms;
65

76
namespace SCVITool
@@ -15,12 +14,20 @@ public MainForm()
1514

1615
private void BackupClicked( object sender, EventArgs e )
1716
{
18-
if( !SaveManager.Backup() )
17+
int index = -1;
18+
19+
slotBox.Text = slotBox.Text.Trim();
20+
21+
if( !int.TryParse( slotBox.Text, out index ) || !SaveManager.Backup( index ) )
1922
MessageBox.Show( this, SaveManager.ErrorMessage, "Backup failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
2023
}
2124
private void RestoreClicked( object sender, EventArgs e )
2225
{
23-
if( !SaveManager.Restore() )
26+
int index = -1;
27+
28+
slotBox.Text = slotBox.Text.Trim();
29+
30+
if( !int.TryParse( slotBox.Text, out index ) || !SaveManager.Restore( index ) )
2431
MessageBox.Show( this, SaveManager.ErrorMessage, "Restore failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
2532
}
2633
}

Source/Program.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ static class Program
1111
static class Version
1212
{
1313
public const uint Major = 0;
14-
public const uint Minor = 1;
15-
public const uint Patch = 1;
14+
public const uint Minor = 2;
15+
public const uint Patch = 0;
1616

1717
public new static string ToString()
1818
{
@@ -29,7 +29,9 @@ static class Version
2929
}
3030

3131
static readonly string About = "SCVITool Version " + Version.ToString();
32-
const string Help = "`SCVITool.exe [arg]`\n`-b` or `-backup` to perform a backup.\n`-r` or `-restore` to reastore the backup.";
32+
const string Help = "`SCVITool.exe [arg] [index]`\n" +
33+
"`-b` or `-backup` to perform a backup. The next available slot will be used if an index is not provided.\n" +
34+
"`-r` or `-restore` to restore the backup. A slot index must be provided or this will fail.";
3335

3436
[STAThread]
3537
static int Main( string[] args )
@@ -38,17 +40,30 @@ static int Main( string[] args )
3840
{
3941
Console.WriteLine( About );
4042

41-
if( args.Length > 1 )
43+
if( args.Length > 2 )
4244
{
4345
Console.WriteLine( Help );
4446
return -1;
4547
}
4648

4749
string arg = args[ 0 ].ToLower();
4850

51+
int index = -1;
52+
53+
if( args.Length > 1 )
54+
{
55+
if( !int.TryParse( args[ 1 ], out index ) )
56+
{
57+
Console.Write( "Unable to parse \"" );
58+
Console.Write( args[ 1 ] );
59+
Console.WriteLine( "\" as an integer." );
60+
return -3;
61+
}
62+
}
63+
4964
if( arg == "-b" || arg == "-backup" )
5065
{
51-
if( !SaveManager.Backup() )
66+
if( !SaveManager.Backup( index ) )
5267
{
5368
Console.Write( "Backup failed: " );
5469
Console.WriteLine( SaveManager.ErrorMessage );
@@ -57,7 +72,7 @@ static int Main( string[] args )
5772
}
5873
else if( arg == "-r" || arg == "-restore" )
5974
{
60-
if( !SaveManager.Restore() )
75+
if( !SaveManager.Restore( index ) )
6176
{
6277
Console.Write( "Restoration failed: " );
6378
Console.WriteLine( SaveManager.ErrorMessage );

Source/SaveManager.cs

+56-17
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@ namespace SCVITool
77
{
88
public static class SaveManager
99
{
10-
static readonly string SavePath = Path.Combine( Environment.GetFolderPath(
11-
Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.None ), "SoulcaliburVI" );
12-
static readonly string SavedPath = Path.Combine( SavePath, "Saved" );
13-
static readonly string BackupPath = Path.Combine( SavePath, "Saved_Backup" );
14-
1510
public static string ErrorMessage
1611
{
1712
get; private set;
1813
} = string.Empty;
1914

20-
public static bool Backup()
15+
public static bool Backup( int index = -1 )
2116
{
22-
if( !Directory.Exists( SavedPath ) )
17+
if( !Directory.Exists( Constants.SavedPath ) )
2318
{
2419
ErrorMessage = "Unable to find save data to backup.";
2520
return false;
@@ -30,12 +25,42 @@ public static bool Backup()
3025

3126
try
3227
{
33-
savedinfo = new DirectoryInfo( SavedPath );
28+
savedinfo = new DirectoryInfo( Constants.SavedPath );
29+
30+
if( index < 0 )
31+
{
32+
string[] files = Directory.GetDirectories( Constants.BackupPath );
33+
34+
for( int i = 0; i < int.MaxValue && index < 0; i++ )
35+
{
36+
string name = "save";
37+
38+
if( i < 10 )
39+
name += '0';
40+
41+
name += i.ToString();
42+
43+
foreach( string f in files )
44+
if( f.ToLower() != name )
45+
index = i;
46+
47+
if( i == int.MaxValue )
48+
throw new InvalidOperationException( "The maximum amount of save slots has been reached." );
49+
}
50+
}
51+
52+
string bpath = "save";
53+
{
54+
if( index < 10 )
55+
bpath += '0';
56+
57+
bpath += index.ToString();
58+
}
3459

35-
if( Directory.Exists( BackupPath ) )
36-
Directory.Delete( BackupPath, true );
60+
if( Directory.Exists( bpath ) )
61+
Directory.Delete( bpath, true );
3762

38-
backupinfo = Directory.CreateDirectory( BackupPath );
63+
backupinfo = Directory.CreateDirectory( bpath );
3964
}
4065
catch( Exception ex )
4166
{
@@ -55,9 +80,23 @@ public static bool Backup()
5580

5681
return true;
5782
}
58-
public static bool Restore()
83+
public static bool Restore( int index )
5984
{
60-
if( !Directory.Exists( BackupPath ) )
85+
if( index < 0 )
86+
{
87+
ErrorMessage = "Cannot restore from an invalid save slot index.";
88+
return false;
89+
}
90+
91+
string bpath = "save";
92+
{
93+
if( index < 10 )
94+
bpath += '0';
95+
96+
bpath += index.ToString();
97+
}
98+
99+
if( !Directory.Exists( bpath ) )
61100
{
62101
ErrorMessage = "No backup save data to restore.";
63102
return false;
@@ -68,12 +107,12 @@ public static bool Restore()
68107

69108
try
70109
{
71-
backupinfo = new DirectoryInfo( BackupPath );
110+
backupinfo = new DirectoryInfo( bpath );
72111

73-
if( Directory.Exists( SavedPath ) )
74-
Directory.Delete( SavedPath, true );
112+
if( Directory.Exists( Constants.SavedPath ) )
113+
Directory.Delete( Constants.SavedPath, true );
75114

76-
savedinfo = new DirectoryInfo( SavedPath );
115+
savedinfo = new DirectoryInfo( Constants.SavedPath );
77116

78117
CopyFilesRecursively( backupinfo, savedinfo );
79118
}

readme.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ Backing up will will check if the `Saved` folder exists, and if so create a copy
1010
Restoring will check if the `Saved_Backup` folder exists, and if so, it will delete the `Saved` folder and replace it with the contents of `Saved_Backup`.<br>
1111

1212
### GUI
13-
The GUI application provides buttons to backup and restore. That's it.
13+
The GUI application provides an option to set a backup slot and has buttons to backup and restore. That's it.
1414

1515
### Console Arguments
16-
`-b` or `-backup` to perform a backup.<br>
17-
`-r` or `-restore` to restore the backup.<br>
16+
`-b [index]` or `-backup [index]` to perform a backup. If the index is ommitted, the next available index will be used.<br>
17+
`-r [index]` or `-restore [index]` to restore the backup. This will fail if a valid index is not provided.<br>
1818

1919
## TODO
20-
- Implement multiple backup "slots" that can be managed in both GUI and console.
20+
- Maybe look into how custom characters are stored and implement some way of backing them up individually if possible.
21+
22+
## Changelog
23+
24+
### Version 0.2.0
25+
- Now backups are stored alongside SCVITool.
26+
- Multiple backup slots are now supported and can be managed in both the GUI and console.
27+
28+
### Version 0.1.1
29+
- Implemented console functionality and refactored the project.
30+
31+
### Version 0.1.0
32+
- Initial release.
33+

0 commit comments

Comments
 (0)