Skip to content

Commit

Permalink
Clean Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Apr 4, 2021
1 parent bdf335c commit 907a389
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/HandyWinget/Assets/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace HandyWinget.Assets
{
public abstract class Consts
public static class Consts
{
public static readonly string AppName = "HandyWinGet";
public static readonly string VersionKey = "VersionCode";
Expand Down
13 changes: 12 additions & 1 deletion src/HandyWinget/Assets/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace HandyWinget.Assets
{
public abstract class Helper
public static class Helper
{
public static ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();

Expand Down Expand Up @@ -114,11 +114,14 @@ public static IEnumerable<string> EnumerateManifest(string rootDirectory)
}
}
}

#region Find Installed App from Registry
private static readonly List<string> _keys = new()
{
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
};

private static List<InstalledAppModel> _installedApps = new();

public static List<InstalledAppModel> GetInstalledApps()
Expand Down Expand Up @@ -160,6 +163,10 @@ private static void FindInstalledApps(RegistryKey regKey, List<string> keys, Lis
}
}
}

#endregion

#region Uninstall Package
public static bool UninstallPackage(string packageName)
{
var result = FindUninstallString(RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64), packageName);
Expand Down Expand Up @@ -207,6 +214,7 @@ private static string MakeUninstallString(string uninstallstring)

return uninstallstring;
}

private static (bool, string) FindUninstallString(RegistryKey regKey, string packageName)
{
foreach (var key in _keys)
Expand Down Expand Up @@ -236,6 +244,8 @@ private static (bool, string) FindUninstallString(RegistryKey regKey, string pac
return (false, string.Empty);
}

#endregion

public static string RemoveComment(string url)
{
var index = url.IndexOf("#");
Expand Down Expand Up @@ -263,6 +273,7 @@ public static void DownloadWithIDM(string link)
Growl.ErrorGlobal("Internet Download Manager (IDM) is not installed on your system, please download and install it first");
}
}

public static string GetExtension(string url)
{
var ext = Path.GetExtension(url);
Expand Down
18 changes: 12 additions & 6 deletions src/HandyWinget/Views/CreatePackage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,31 @@ namespace HandyWinget.Views
/// </summary>
public partial class CreatePackage : UserControl, INotifyPropertyChanged
{
#region INotify
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private ObservableCollection<Installer> installers = new ObservableCollection<Installer>();
#endregion

private ObservableCollection<Installer> installers = new ObservableCollection<Installer>();
public ObservableCollection<Installer> Installers
{
get { return installers; }
set
{
installers = value;
RaisePropertyChanged();
RaisePropertyChanged(nameof(installers));
}
}

public CreatePackage()
{
InitializeComponent();
DataContext = this;

if (Helper.IsWingetInstalled())
{
btnValidate.IsEnabled = true;
Expand Down Expand Up @@ -89,12 +92,14 @@ public void ClearInputs()
prgStatus.Value = 0;
Installers.Clear();
}

public void GenerateScript()
{
try
{
if (!string.IsNullOrEmpty(txtAppName.Text) && !string.IsNullOrEmpty(txtPublisher.Text) && !string.IsNullOrEmpty(txtId.Text) && !string.IsNullOrEmpty(txtVersion.Text)
&& !string.IsNullOrEmpty(txtLicense.Text) && !string.IsNullOrEmpty(txtUrl.Text) && txtUrl.Text.IsUrl())
if (!string.IsNullOrEmpty(txtAppName.Text) && !string.IsNullOrEmpty(txtPublisher.Text) &&
!string.IsNullOrEmpty(txtId.Text) && !string.IsNullOrEmpty(txtVersion.Text) &&
!string.IsNullOrEmpty(txtLicense.Text) && !string.IsNullOrEmpty(txtUrl.Text) && txtUrl.Text.IsUrl())
{
var versionBuilder = new ExportVersionModel
{
Expand Down Expand Up @@ -154,8 +159,9 @@ public void GenerateScript(GenerateScriptMode mode)
{
try
{
if (!string.IsNullOrEmpty(txtAppName.Text) && !string.IsNullOrEmpty(txtPublisher.Text) && !string.IsNullOrEmpty(txtId.Text) && !string.IsNullOrEmpty(txtVersion.Text)
&& !string.IsNullOrEmpty(txtLicense.Text) && !string.IsNullOrEmpty(txtUrl.Text) && txtUrl.Text.IsUrl())
if (!string.IsNullOrEmpty(txtAppName.Text) && !string.IsNullOrEmpty(txtPublisher.Text) &&
!string.IsNullOrEmpty(txtId.Text) && !string.IsNullOrEmpty(txtVersion.Text) &&
!string.IsNullOrEmpty(txtLicense.Text) && !string.IsNullOrEmpty(txtUrl.Text) && txtUrl.Text.IsUrl())
{
var builder = new YamlPackageModel
{
Expand Down
4 changes: 2 additions & 2 deletions src/HandyWinget/Views/General.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ private void LoadInitialSettings()
switch (Settings.InstallMode)
{
case InstallMode.Wingetcli:
tgIDM.Visibility = System.Windows.Visibility.Collapsed;
tgIDM.Visibility = Visibility.Collapsed;
break;
case InstallMode.Internal:
tgIDM.Visibility = System.Windows.Visibility.Visible;
tgIDM.Visibility = Visibility.Visible;
break;
}

Expand Down
Loading

0 comments on commit 907a389

Please sign in to comment.