Skip to content

Commit

Permalink
Fix a bug that packages were not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Feb 28, 2021
1 parent 48c09ac commit 9393fd0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/HandyWinget/Assets/Enums/IdentifyPackageMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public enum IdentifyPackageMode
[Description("Off (Fast)")]
Off,

[Description("Internal Method (Normal)")]
[Description("Internal Method")]
Internal,

[Description("Winget-cli Method (Slow)")]
[Description("Winget-cli Method")]
Wingetcli
}
}
2 changes: 1 addition & 1 deletion src/HandyWinget/Assets/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ISettings : JsonSettings
public virtual bool GroupByPublisher { get; set; } = false;
public virtual DataGridRowDetailsVisibilityMode ShowExtraDetails { get; set; } = DataGridRowDetailsVisibilityMode.Collapsed;
public virtual NavigationViewPaneDisplayMode PaneDisplayMode { get; set; } = NavigationViewPaneDisplayMode.Top;
public virtual InstallMode InstallMode { get; set; } = InstallMode.Wingetcli;
public virtual InstallMode InstallMode { get; set; } = InstallMode.Internal;
public virtual IdentifyPackageMode IdentifyPackageMode { get; set; } = IdentifyPackageMode.Off;
public virtual ApplicationTheme Theme { get; set; } = ApplicationTheme.Light;
public virtual Brush Accent { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/HandyWinget/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void OpenTerminal_Click(object sender, RoutedEventArgs e)

private void appBarRefresh_Click(object sender, RoutedEventArgs e)
{
Packages.Instance.LoadManifests(true);
Packages.Instance.DownloadManifests(true);
}

private void appBarExport_Click(object sender, RoutedEventArgs e)
Expand Down
47 changes: 28 additions & 19 deletions src/HandyWinget/Views/Packages.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public Packages()
BindingOperations.EnableCollectionSynchronization(DataList, Lock);
BindingOperations.EnableCollectionSynchronization(_temoList, Lock);
BindingOperations.EnableCollectionSynchronization(_tempVersions, Lock);
LoadManifests();
InitSettings();
DownloadManifests();
SetDataListGrouping();
}

private void InitSettings()
private void SetDataListGrouping()
{
dataGrid.RowDetailsVisibilityMode = Settings.ShowExtraDetails;

Expand All @@ -69,11 +69,8 @@ private void InitSettings()
}
}

public async void LoadManifests(bool IsRefresh = false)
public async void DownloadManifests(bool IsRefresh = false)
{
int _totalmanifestsCount = 0;
int _currentManifestCount = 0;

DataList?.Clear();
_temoList?.Clear();
_tempVersions?.Clear();
Expand All @@ -83,29 +80,40 @@ public async void LoadManifests(bool IsRefresh = false)
tgCancelDownload.Visibility = Visibility.Collapsed;

MainWindow.Instance.CommandButtonsVisibility(Visibility.Collapsed);

if (Helper.IsConnectedToInternet())
bool _isConnected = Helper.IsConnectedToInternet();
if ((_isConnected && !Directory.Exists(Consts.ManifestPath)) || (_isConnected && IsRefresh is true))
{
if (!Directory.Exists(Consts.ManifestPath) || IsRefresh is true)
if (IsRefresh)
{
if (IsRefresh)
{
txtStatus.Text = "Refreshing Packages...";
}
var manifestUrl = Consts.WingetPkgsRepository;
txtStatus.Text = "Refreshing Packages...";
}
var manifestUrl = Consts.WingetPkgsRepository;

WebClient client = new WebClient();
WebClient client = new WebClient();

client.DownloadFileCompleted += Client_DownloadFileCompleted;
client.DownloadProgressChanged += Client_DownloadProgressChanged;
await client.DownloadFileTaskAsync(new Uri(manifestUrl), Consts.RootPath + @"\winget-pkgs-master.zip");
client.DownloadFileCompleted += Client_DownloadFileCompleted;
client.DownloadProgressChanged += Client_DownloadProgressChanged;
await client.DownloadFileTaskAsync(new Uri(manifestUrl), Consts.RootPath + @"\winget-pkgs-master.zip");

}
else if (Directory.Exists(Consts.ManifestPath))
{
if (!_isConnected && IsRefresh)
{
Growl.WarningGlobal("Unable to connect to the Internet, we Load local packages.");
}
LoadLocalManifests();
}
else
{
Growl.ErrorGlobal("Unable to connect to the Internet");
}
}

private async void LoadLocalManifests()
{
int _totalmanifestsCount = 0;
int _currentManifestCount = 0;
if (Directory.Exists(Consts.ManifestPath))
{
prgStatus.IsIndeterminate = false;
Expand Down Expand Up @@ -277,6 +285,7 @@ await Task.Run(()=> {
}
}
});
LoadLocalManifests();
}

private async void tgCancelDownload_Checked(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 9393fd0

Please sign in to comment.