-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
*.swp | ||
*.*~ | ||
project.lock.json | ||
.DS_Store | ||
*.pyc | ||
nupkg/ | ||
|
||
# Visual Studio Code | ||
.vscode | ||
|
||
# Rider | ||
.idea | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
x64/ | ||
x86/ | ||
build/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Oo]ut/ | ||
msbuild.log | ||
msbuild.err | ||
msbuild.wrn | ||
|
||
# Visual Studio 2015 | ||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Application x:Class="Sungaila.SUBSTitute.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
DispatcherUnhandledException="Application_DispatcherUnhandledException" | ||
StartupUri="Views/MainWindow.xaml" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
|
||
namespace Sungaila.SUBSTitute | ||
{ | ||
public partial class App : Application | ||
{ | ||
private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) | ||
{ | ||
if (MessageBox.Show(MainWindow, | ||
$"The following unexpected error has occured:{Environment.NewLine}{Environment.NewLine}{e.Exception.Message}{Environment.NewLine}{Environment.NewLine}[OK] will terminate this application.{Environment.NewLine}[Cancel] will keep the application running but it might be unstable from now on.", | ||
"Unexpected error", | ||
MessageBoxButton.OKCancel, | ||
MessageBoxImage.Error) != MessageBoxResult.OK) | ||
e.Handled = true; | ||
} | ||
|
||
private void Application_Exit(object sender, ExitEventArgs e) | ||
{ | ||
MainWindowViewModel? viewModel = MainWindow.DataContext as MainWindowViewModel; | ||
|
||
if (viewModel == null) | ||
return; | ||
|
||
UserSettings.Save(new UserSettings | ||
{ | ||
LastSelectedDriveLetter = viewModel.SelectedMapping?.DriveLetter, | ||
LastBrowserRootDirectory = viewModel.BrowserRootDirectory | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class BrowserGotoParentDirectoryCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
if (String.IsNullOrEmpty(parameter.BrowserRootDirectory)) | ||
return; | ||
|
||
DirectoryInfo dirInfo = new DirectoryInfo(parameter.BrowserRootDirectory); | ||
|
||
if (!dirInfo.Exists || dirInfo.Parent == null) | ||
return; | ||
|
||
parameter.BrowserRootDirectory = dirInfo.Parent.FullName; | ||
} | ||
|
||
public override bool CanExecute(MainWindowViewModel parameter) | ||
{ | ||
if (!base.CanExecute(parameter) || String.IsNullOrEmpty(parameter.BrowserRootDirectory)) | ||
return false; | ||
|
||
DirectoryInfo dirInfo = new DirectoryInfo(parameter.BrowserRootDirectory); | ||
|
||
return dirInfo.Exists && dirInfo.Parent != null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class MapDriveCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
if (parameter.SelectedMapping == null || parameter.SelectedMapping.Directory == null) | ||
return; | ||
|
||
char driveLetter = parameter.SelectedMapping.DriveLetter; | ||
|
||
try | ||
{ | ||
Win32.DosDevice.MapDrive(driveLetter, parameter.SelectedMapping.Directory); | ||
parameter.UpdateAvailableMappings(driveLetter); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show($"Failed to map drive letter {driveLetter}.{Environment.NewLine}{ex.Message}", "Failed to map", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
} | ||
|
||
public override bool CanExecute(MainWindowViewModel parameter) | ||
{ | ||
return base.CanExecute(parameter) && | ||
parameter.SelectedMapping != null && | ||
!String.IsNullOrEmpty(parameter.SelectedMapping.Directory) && | ||
(parameter.SelectedMapping.InitialDirectory == null || parameter.SelectedMapping.Directory != parameter.SelectedMapping.InitialDirectory); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class SelectBrowserDirectoryCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
var openDirectoryDialog = new CommonOpenFileDialog | ||
{ | ||
IsFolderPicker = true, | ||
InitialDirectory = parameter.BrowserRootDirectory | ||
}; | ||
|
||
if (openDirectoryDialog.ShowDialog() == CommonFileDialogResult.Ok) | ||
parameter.BrowserRootDirectory = openDirectoryDialog.FileName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class SelectMappedDirectoryCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
if (parameter.SelectedMapping == null) | ||
return; | ||
|
||
DirectoryInfo? dirInfo = parameter.SelectedMapping.Directory != null | ||
? new DirectoryInfo(parameter.SelectedMapping.Directory) | ||
: null; | ||
|
||
var openDirectoryDialog = new CommonOpenFileDialog | ||
{ | ||
IsFolderPicker = true, | ||
InitialDirectory = dirInfo != null && dirInfo.Exists && dirInfo.Parent != null ? dirInfo.Parent.FullName : null | ||
}; | ||
|
||
if (openDirectoryDialog.ShowDialog() == CommonFileDialogResult.Ok) | ||
parameter.SelectedMapping.Directory = openDirectoryDialog.FileName; | ||
} | ||
|
||
public override bool CanExecute(MainWindowViewModel parameter) | ||
{ | ||
return base.CanExecute(parameter) && parameter.SelectedMapping != null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class UnmapAllDrivesCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
bool failed = false; | ||
char? selectedDrive = parameter.SelectedMapping?.DriveLetter; | ||
|
||
StringBuilder errorMessage = new StringBuilder("Failed to unmap the following drive letters:"); | ||
|
||
foreach (MappingViewModel mapping in parameter.Mappings.Where(mapping => mapping.IsDirectoryMapped)) | ||
{ | ||
char driveLetter = mapping.DriveLetter; | ||
|
||
try | ||
{ | ||
Win32.DosDevice.UnmapDrive(driveLetter); | ||
} | ||
catch (Exception ex) | ||
{ | ||
failed = true; | ||
errorMessage.Append($"{Environment.NewLine}{driveLetter} - {ex.Message}"); | ||
} | ||
} | ||
|
||
parameter.UpdateAvailableMappings(selectedDrive); | ||
|
||
if (failed) | ||
MessageBox.Show(errorMessage.ToString(), "Failed to unmap all drives", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
|
||
public override bool CanExecute(MainWindowViewModel parameter) | ||
{ | ||
return base.CanExecute(parameter) && parameter.Mappings.Any(mapping => mapping.IsDirectoryMapped); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
using Sungaila.SUBSTitute.Core; | ||
using Sungaila.SUBSTitute.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows; | ||
|
||
namespace Sungaila.SUBSTitute.Command | ||
{ | ||
public class UnmapDriveCommand | ||
: ViewModelCommand<MainWindowViewModel> | ||
{ | ||
public override void Execute(MainWindowViewModel parameter) | ||
{ | ||
if (parameter.SelectedMapping == null) | ||
return; | ||
|
||
char driveLetter = parameter.SelectedMapping.DriveLetter; | ||
|
||
try | ||
{ | ||
Win32.DosDevice.UnmapDrive(driveLetter); | ||
parameter.UpdateAvailableMappings(driveLetter); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show($"Failed to unmap drive letter {driveLetter}.{Environment.NewLine}{ex.Message}", "Failed to unmap", MessageBoxButton.OK, MessageBoxImage.Error); | ||
} | ||
} | ||
|
||
public override bool CanExecute(MainWindowViewModel parameter) | ||
{ | ||
return base.CanExecute(parameter) && parameter.SelectedMapping != null && parameter.SelectedMapping.IsDirectoryMapped; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace Sungaila.SUBSTitute.Converters | ||
{ | ||
[ValueConversion(typeof(bool), typeof(FontWeight))] | ||
public class BoolToFontWeightConverter | ||
: IValueConverter | ||
{ | ||
public static readonly BoolToFontWeightConverter Instance = new BoolToFontWeightConverter(); | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (!(value is bool)) | ||
return Binding.DoNothing; | ||
|
||
return ((bool)value) ? FontWeights.ExtraBold : FontWeights.Normal; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace Sungaila.SUBSTitute.Converters | ||
{ | ||
[ValueConversion(typeof(bool), typeof(GridLength))] | ||
public class BoolToGridLengthConverter | ||
: IValueConverter | ||
{ | ||
public static readonly BoolToGridLengthConverter Instance = new BoolToGridLengthConverter(); | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (!(value is bool)) | ||
return Binding.DoNothing; | ||
|
||
return (bool)value ? new GridLength(1.0, GridUnitType.Star) : GridLength.Auto; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.