Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Aug 19, 2020
2 parents fa1f3c5 + b5f88da commit ed8889f
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Mutagen.Bethesda.Synthesis/Mutagen.Bethesda.Synthesis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/Noggog/Synthesis</RepositoryUrl>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<AssemblyName>Mutagen.Bethesda.Synthesis</AssemblyName>
<Version>0.0.2</Version>
<Version>0.0.2.1</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand All @@ -21,8 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mutagen.Bethesda" Version="0.13.0" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="0.13.0" />
<PackageReference Include="Mutagen.Bethesda" Version="0.13.2" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="0.13.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Company>Mutagen</Company>
<Product>Synthesis</Product>
<PackageId>Synthesis.Bethesda.Execution</PackageId>
<Version>0.0.2</Version>
<Version>0.0.2.1</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand All @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.7.0" />
<PackageReference Include="Mutagen.Bethesda.Core" Version="0.13.0" />
<PackageReference Include="Mutagen.Bethesda.Core" Version="0.13.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Noggog.CSharpExt" Version="1.1.0" />
</ItemGroup>
Expand Down
172 changes: 172 additions & 0 deletions Synthesis.Bethesda.GUI/OpenWithProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// /*
// Copyright (C) 2020 erri120
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Win32;

namespace Synthesis.Bethesda.GUI
{
public enum OpenWithEnum
{
[Description("None")]
None,
[Description("System Default")]
SystemDefault,
[Description("Visual Studio")]
VisualStudio,
[Description("Rider")]
Rider,
[Description("Visual Code")]
VisualCode
}

public static class OpenWithProgram
{
private static readonly string? RiderPath;
private static readonly string? VSPath;

static OpenWithProgram()
{
#region Visual Studio

{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var vsMainDir = Path.Combine(programFiles, "Microsoft Visual Studio");
List<int>? versions = Directory.EnumerateDirectories(vsMainDir, "*", SearchOption.TopDirectoryOnly)
.Select(x =>
{
ReadOnlySpan<char> span = x.AsSpan(vsMainDir[^1] == Path.PathSeparator ? vsMainDir.Length : vsMainDir.Length+1);
if(int.TryParse(span.ToString(), out var y))
return y;
return -1;
})
.Where(x => x != -1)
.ToList();
var currentVersion = versions.Max();
//TODO: assuming Community Version for now
var exePath = Path.Combine(vsMainDir, $"{currentVersion}", "Community", "Common7", "IDE", "devenv.exe");
if (File.Exists(exePath))
VSPath = exePath;
}

#endregion

#region Rider
{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var defaultRiderLocation = Path.Combine(programFiles, "JetBrains", "JetBrains Rider", "bin");
if (Directory.Exists(defaultRiderLocation))
{
var exePath = Path.Combine(defaultRiderLocation, "rider64.exe");
if(File.Exists(exePath))
RiderPath = exePath;
}
else
{
const string toolBoxRegKey = @"Software\JetBrains\Toolbox";
var toolBoxKey = Registry.CurrentUser.OpenSubKey(toolBoxRegKey);
var toolboxBinPath = toolBoxKey?.GetValue("");
if (toolboxBinPath == null)
return;

var toolBoxPath = Path.GetDirectoryName(toolboxBinPath.ToString());

const string riderVersionRegKey = @"Software\JetBrains\Rider";
var riderVersionKey = Registry.CurrentUser.OpenSubKey(riderVersionRegKey);
var riderVersion = riderVersionKey?.GetValue("");
if (riderVersion == null)
return;

var exePath = Path.Combine(toolBoxPath ?? string.Empty, "apps", "Rider", "ch-0",
riderVersion.ToString() ?? string.Empty, "bin", "rider64.exe");

if(File.Exists(exePath))
RiderPath = exePath;
}
}

#endregion
}

public static void OpenSolution(string path, OpenWithEnum option)
{
switch (option)
{
case OpenWithEnum.None:
break;
case OpenWithEnum.SystemDefault:
{
Process.Start(new ProcessStartInfo(path)
{
UseShellExecute = true,
});
break;
}
case OpenWithEnum.VisualStudio:
{
if (VSPath == null)
break;

var info = new ProcessStartInfo
{
FileName = VSPath,
ArgumentList = { path },
UseShellExecute = true
};

Process.Start(info);
break;
}
case OpenWithEnum.Rider:
{
if (RiderPath == null)
break;

var info = new ProcessStartInfo
{
FileName = RiderPath,
ArgumentList = { path },
UseShellExecute = true
};

Process.Start(info);

break;
}
case OpenWithEnum.VisualCode:
{
var info = new ProcessStartInfo
{
FileName = "code",
ArgumentList = { "." },
WorkingDirectory = Path.GetDirectoryName(path)!,
UseShellExecute = true
};
Process.Start(info);
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
2 changes: 1 addition & 1 deletion Synthesis.Bethesda.GUI/Settings/SynthesisGuiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SynthesisGuiSettings
{
public SynthesisSettings ExecutableSettings = new SynthesisSettings();
public bool ShowHelp = true;
public bool OpenVsAfterCreating = true;
public OpenWithEnum OpenWithProgram = OpenWithEnum.VisualStudio;
public string MainRepositoryFolder = string.Empty;
}
}
2 changes: 1 addition & 1 deletion Synthesis.Bethesda.GUI/Synthesis.Bethesda.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<RepositoryUrl>https://github.com/Noggog/Synthesis</RepositoryUrl>
<Company>Mutagen</Company>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public SynthesisGuiSettings Save()
},
ShowHelp = ShowHelp,
MainRepositoryFolder = MainVM.Settings.MainRepositoryFolder,
OpenVsAfterCreating = MainVM.Settings.OpenVsAfterCreating,
OpenWithProgram = MainVM.Settings.OpenWithProgram
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using DynamicData.Binding;

namespace Synthesis.Bethesda.GUI
{
Expand All @@ -32,14 +33,18 @@ public class SolutionPatcherInitVM : PatcherInitVM
private readonly ObservableAsPropertyHelper<Func<SolutionPatcherVM, Task>?> _TargetSolutionInitializer;
public Func<SolutionPatcherVM, Task>? TargetSolutionInitializer => _TargetSolutionInitializer.Value;

public ObservableCollectionExtended<OpenWithEnum> OpenWithOptions { get; } = new ObservableCollectionExtended<OpenWithEnum>();

[Reactive]
public bool OpenVsAfter { get; set; }
public OpenWithEnum OpenWith { get; set; }

public SolutionPatcherInitVM(SolutionPatcherVM patcher)
{
_patcher = patcher;
OpenVsAfter = _patcher.Profile.Config.MainVM.Settings.OpenVsAfterCreating;
OpenWith = _patcher.Profile.Config.MainVM.Settings.OpenWithProgram;
New.ParentDirPath.TargetPath = _patcher.Profile.Config.MainVM.Settings.MainRepositoryFolder;

OpenWithOptions.AddRange(EnumExt.GetValues<OpenWithEnum>());

var initializer = this.WhenAnyValue(x => x.SelectedIndex)
.Select<int, ASolutionInitializer>(x =>
Expand Down Expand Up @@ -68,27 +73,21 @@ public override async Task ExecuteChanges()
{
if (TargetSolutionInitializer == null) return;
await TargetSolutionInitializer(_patcher);
if (OpenVsAfter)
try
{
try
{
Process.Start(new ProcessStartInfo(_patcher.SolutionPath.TargetPath)
{
UseShellExecute = true,
});
}
catch (Exception)
{
// ToDo
// Log
}
OpenWithProgram.OpenSolution(_patcher.SolutionPath.TargetPath, OpenWith);
}
catch (Exception)
{
//TODO
//log
}
}

public override void Dispose()
{
base.Dispose();
_patcher.Profile.Config.MainVM.Settings.OpenVsAfterCreating = OpenVsAfter;
_patcher.Profile.Config.MainVM.Settings.OpenWithProgram = OpenWith;
_patcher.Profile.Config.MainVM.Settings.MainRepositoryFolder = New.ParentDirPath.TargetPath;
}

Expand Down
20 changes: 16 additions & 4 deletions Synthesis.Bethesda.GUI/Views/Initialization/SolutionInitView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:noggog="clr-namespace:Noggog.WPF;assembly=Noggog.WPF"
xmlns:gui="clr-namespace:Synthesis.Bethesda.GUI"
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
Expand Down Expand Up @@ -119,10 +121,20 @@
</Grid>
</TabItem>
</TabControl>
<CheckBox Grid.Row="1"
x:Name="OpenVsAfter"
Margin="10,15,0,6"
Content="Open Visual Studio After Creating" />
<Grid Grid.Row="1" Margin="0,15,0,6">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="0 4" Text="Open With"/>
<ComboBox x:Name="OpenWithComboBox" Grid.Row="1">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<Grid Grid.Row="2"
x:Name="HelpBox"
Margin="0,25,0,0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public SolutionInitView()
.DisposeWith(dispose);

// Bind open after checkbox
this.BindStrict(this.ViewModel, vm => vm.OpenVsAfter, view => view.OpenVsAfter.IsChecked)
this.BindStrict(ViewModel, vm => vm.OpenWithOptions, view => view.OpenWithComboBox.ItemsSource)
.DisposeWith(dispose);
this.BindStrict(ViewModel, vm => vm.OpenWith, view => view.OpenWithComboBox.SelectedValue)
.DisposeWith(dispose);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Mutagen.Bethesda" Version="0.13.0" />
<PackageReference Include="Mutagen.Bethesda" Version="0.13.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions Synthesis.Bethesda/Synthesis.Bethesda.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/Noggog/Synthesis</RepositoryUrl>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<AssemblyName>Synthesis.Bethesda</AssemblyName>
<Version>0.0.2</Version>
<Version>0.0.2.1</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand All @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="0.13.0" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="0.13.2" />
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
Expand Down

0 comments on commit ed8889f

Please sign in to comment.