Linking Data instead of making new copies, checking if EZPPClient is running, added Desktop Shortcut
This commit is contained in:
parent
2e795ad2e4
commit
65b4abc334
|
@ -93,6 +93,8 @@
|
|||
<Compile Include="MD5File.cs" />
|
||||
<Compile Include="DownloadUtil.cs" />
|
||||
<Compile Include="MD5Util.cs" />
|
||||
<Compile Include="ProcessUtil.cs" />
|
||||
<Compile Include="Shortcut.cs" />
|
||||
<Compile Include="UpdateState.cs" />
|
||||
<Compile Include="Util.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
|
@ -134,6 +136,9 @@
|
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="DK.WshRuntime">
|
||||
<Version>4.1.3.201115164</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ModernWpfUI">
|
||||
<Version>0.9.4</Version>
|
||||
</PackageReference>
|
||||
|
|
|
@ -1,28 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Microsoft.Win32;
|
||||
using System.IO;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using System.Net;
|
||||
using System.Globalization;
|
||||
using ModernWpf.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Media;
|
||||
using System.Threading;
|
||||
using Windows.System;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Shortcut;
|
||||
using Path = System.Windows.Shapes.Path;
|
||||
|
||||
#if DEBUG
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
#endif
|
||||
|
||||
namespace EZPPClient_Installer
|
||||
{
|
||||
|
@ -67,6 +63,12 @@ namespace EZPPClient_Installer
|
|||
InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", ".");
|
||||
|
||||
string osuPath = Util.osuInstallDir();
|
||||
|
||||
if (osuPath.EndsWith(@"\EZPPClient"))
|
||||
{
|
||||
osuPath = osuPath.Replace(@"\EZPPClient", "");
|
||||
}
|
||||
|
||||
bool isValidFolder = await isValidOsuFolder(osuPath);
|
||||
UpdateInstallButton(!string.IsNullOrEmpty(osuPath));
|
||||
|
||||
|
@ -193,6 +195,17 @@ namespace EZPPClient_Installer
|
|||
|
||||
string EZPPFolder = osuFolder + @"\EZPPClient";
|
||||
|
||||
if (ProcessUtil.ProgramIsRunning(folderTextbox.Text + @"\EZPPClient.exe"))
|
||||
{
|
||||
_ = new ContentDialog()
|
||||
{
|
||||
Title = "Oops..",
|
||||
Content = "The EZPPClient is currently running.",
|
||||
PrimaryButtonText = "Oh"
|
||||
}.ShowAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (InstallButton.Content.Equals("Install"))
|
||||
{
|
||||
if (linkFoldersCheckbox.IsChecked.Value)
|
||||
|
@ -251,14 +264,24 @@ namespace EZPPClient_Installer
|
|||
{
|
||||
try
|
||||
{
|
||||
File.Copy(string.Format(@"{0}\osu!.{1}.cfg", osuFolder, userName), string.Format(@"{0}\osu!.{1}.cfg", EZPPFolder, userName));
|
||||
//File.Copy(string.Format(@"{0}\osu!.{1}.cfg", osuFolder, userName), string.Format(@"{0}\osu!.{1}.cfg", EZPPFolder, userName));
|
||||
if (!CreateSymbolicLink(string.Format(@"{0}\osu!.{1}.cfg", EZPPFolder, userName), string.Format(@"{0}\osu!.{1}.cfg", osuFolder, userName), SymbolicLink.File))
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to create Symlink to cfg file.",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = string.Format("Failed to copy osu!.{0}.cfg", userName),
|
||||
Content = string.Format("Failed to link osu!.{0}.cfg", userName),
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
|
@ -268,14 +291,24 @@ namespace EZPPClient_Installer
|
|||
{
|
||||
try
|
||||
{
|
||||
File.Copy(string.Format(@"{0}\scores.db", osuFolder), string.Format(@"{0}\scores.db", EZPPFolder));
|
||||
//File.Copy(string.Format(@"{0}\scores.db", osuFolder), string.Format(@"{0}\scores.db", EZPPFolder));
|
||||
if (!CreateSymbolicLink(string.Format(@"{0}\scores.db", EZPPFolder), string.Format(@"{0}\scores.db", osuFolder), SymbolicLink.File))
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to create Symlink to scores.db file.",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to copy scores.db",
|
||||
Content = "Failed to link scores.db",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
|
@ -285,14 +318,51 @@ namespace EZPPClient_Installer
|
|||
{
|
||||
try
|
||||
{
|
||||
File.Copy(string.Format(@"{0}\collection.db", osuFolder), string.Format(@"{0}\collection.db", EZPPFolder));
|
||||
//File.Copy(string.Format(@"{0}\collection.db", osuFolder), string.Format(@"{0}\collection.db", EZPPFolder));
|
||||
if (!CreateSymbolicLink(string.Format(@"{0}\collection.db", EZPPFolder), string.Format(@"{0}\collection.db", osuFolder), SymbolicLink.File))
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to create Symlink to collection.db file.",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to copy collection.db",
|
||||
Content = "Failed to link collection.db",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
}
|
||||
}
|
||||
if (File.Exists(string.Format(@"{0}\osu!.db", osuFolder)) && !File.Exists(string.Format(@"{0}\osu!.db", EZPPFolder)))
|
||||
{
|
||||
try
|
||||
{
|
||||
//File.Copy(string.Format(@"{0}\osu.db", osuFolder), string.Format(@"{0}\osu.db", EZPPFolder));
|
||||
if (!CreateSymbolicLink(string.Format(@"{0}\osu!.db", EZPPFolder), string.Format(@"{0}\osu!.db", osuFolder), SymbolicLink.File))
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to create Symlink to osu!.db file.",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ContentDialog dg = new ContentDialog()
|
||||
{
|
||||
Title = "Hmmm..",
|
||||
Content = "Failed to link osu!.db",
|
||||
PrimaryButtonText = "Okay :/"
|
||||
};
|
||||
await dg.ShowAsync();
|
||||
|
@ -318,6 +388,22 @@ namespace EZPPClient_Installer
|
|||
|
||||
await DownloadUtil.DownloadFiles(filesToDownload, EZPPFolder);
|
||||
|
||||
if (InstallButton.Content.Equals("Install"))
|
||||
{
|
||||
IShellLink link = (IShellLink)new ShellLink();
|
||||
|
||||
// setup shortcut information
|
||||
link.SetDescription("Starts the EZPPClient");
|
||||
link.SetPath(EZPPFolder + @"\EZPPClient.exe");
|
||||
|
||||
// save it
|
||||
IPersistFile file = (IPersistFile)link;
|
||||
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
|
||||
string LinkFile = System.IO.Path.Combine(desktopPath, "Start EZPPClient.lnk");
|
||||
Console.Out.WriteLine("Saving Shortcut to " + LinkFile);
|
||||
file.Save(LinkFile, false);
|
||||
}
|
||||
|
||||
InstallButton.Visibility = prevInstallBtnVis;
|
||||
Uninstall_Button.Visibility = prevUninstallBtnVis;
|
||||
linkFoldersCheckbox.Visibility = prevLinkFCVis;
|
||||
|
@ -329,8 +415,7 @@ namespace EZPPClient_Installer
|
|||
Uninstall_Button.Visibility = Visibility.Visible;
|
||||
UpdateInstallButton(false);
|
||||
|
||||
string osuEZPPPath = folderTextbox.Text + @"\EZPPClient";
|
||||
List<string> outdatedFiles = DownloadUtil.FilesToDownload(osuEZPPPath, false);
|
||||
List<string> outdatedFiles = DownloadUtil.FilesToDownload(EZPPFolder, false);
|
||||
|
||||
if (!IsEmpty(outdatedFiles))
|
||||
{
|
||||
|
@ -447,6 +532,16 @@ namespace EZPPClient_Installer
|
|||
|
||||
private async void Uninstall_Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(ProcessUtil.ProgramIsRunning(folderTextbox.Text + @"\EZPPClient.exe"))
|
||||
{
|
||||
_ = new ContentDialog()
|
||||
{
|
||||
Title = "Oops..",
|
||||
Content = "The EZPPClient is currently running.",
|
||||
PrimaryButtonText = "Oh"
|
||||
}.ShowAsync();
|
||||
return;
|
||||
}
|
||||
SystemSounds.Asterisk.Play();
|
||||
ContentDialog cd = new ContentDialog()
|
||||
{
|
||||
|
@ -462,6 +557,11 @@ namespace EZPPClient_Installer
|
|||
if (Directory.Exists(osuEZPPPath))
|
||||
Directory.Delete(osuEZPPPath, true);
|
||||
|
||||
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
|
||||
string linkFile = System.IO.Path.Combine(desktopPath, "Start EZPPClient.lnk");
|
||||
if (File.Exists(linkFile))
|
||||
File.Delete(linkFile);
|
||||
|
||||
_ = new ContentDialog()
|
||||
{
|
||||
Title = "Success!",
|
||||
|
|
33
EZPPClient Installer/ProcessUtil.cs
Normal file
33
EZPPClient Installer/ProcessUtil.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EZPPClient_Installer
|
||||
{
|
||||
class ProcessUtil
|
||||
{
|
||||
public static bool ProgramIsRunning(string FullPath)
|
||||
{
|
||||
string FilePath = Path.GetDirectoryName(FullPath);
|
||||
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
|
||||
bool isRunning = false;
|
||||
|
||||
Process[] pList = Process.GetProcessesByName(FileName);
|
||||
|
||||
foreach (Process p in pList)
|
||||
{
|
||||
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
isRunning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isRunning;
|
||||
}
|
||||
}
|
||||
}
|
39
EZPPClient Installer/Shortcut.cs
Normal file
39
EZPPClient Installer/Shortcut.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
|
||||
namespace Shortcut
|
||||
{
|
||||
[ComImport]
|
||||
[Guid("00021401-0000-0000-C000-000000000046")]
|
||||
internal class ShellLink
|
||||
{
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
[Guid("000214F9-0000-0000-C000-000000000046")]
|
||||
internal interface IShellLink
|
||||
{
|
||||
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, int fFlags);
|
||||
void GetIDList(out IntPtr ppidl);
|
||||
void SetIDList(IntPtr pidl);
|
||||
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
|
||||
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
|
||||
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
|
||||
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
|
||||
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
|
||||
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
|
||||
void GetHotkey(out short pwHotkey);
|
||||
void SetHotkey(short wHotkey);
|
||||
void GetShowCmd(out int piShowCmd);
|
||||
void SetShowCmd(int iShowCmd);
|
||||
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon);
|
||||
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
|
||||
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
|
||||
void Resolve(IntPtr hwnd, int fFlags);
|
||||
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user