Skip to content

Commit

Permalink
Fixed TgDownloaderConsole, added auto update progress when downloadin…
Browse files Browse the repository at this point in the history
…g in TgDownloaderWinDesktop
  • Loading branch information
DamianMorozov committed Nov 9, 2023
1 parent b6333fb commit 33cca40
Show file tree
Hide file tree
Showing 37 changed files with 415 additions and 173 deletions.
21 changes: 12 additions & 9 deletions Clients/TgDownloaderConsole/Helpers/TgMenuHelperDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
// ReSharper disable InconsistentNaming

using TgDownloader.Models;

namespace TgDownloaderConsole.Helpers;

internal partial class TgMenuHelper
Expand Down Expand Up @@ -101,8 +103,8 @@ private TgDownloadSettingsModel SetupDownloadSource(long? id = null)
TgDownloadSettingsModel tgDownloadSettings = TgDownloadSettingsModel.CreateNew();
//tgDownloadSettings.SourceVm.SourceFirstId = 1;
SetupDownloadSourceCore(id, tgDownloadSettings);
Channel? channel = TgClient.PrepareChannelDownloadMessagesAsync(tgDownloadSettings, true).GetAwaiter().GetResult();
if (channel is null)
TgDownloadSmartSource smartSource = TgClient.PrepareChannelDownloadMessagesAsync(tgDownloadSettings, true).GetAwaiter().GetResult();
if (smartSource.Channel is null)
_ = TgClient.PrepareChatBaseDownloadMessagesAsync(tgDownloadSettings, true).GetAwaiter().GetResult();
LoadTgClientSettings(tgDownloadSettings, false, false);
return tgDownloadSettings;
Expand Down Expand Up @@ -136,18 +138,18 @@ private void SetupDownloadSourceCore(long? id, TgDownloadSettingsModel tgDownloa

private async Task SetupDownloadSourceFirstIdAutoAsync(TgDownloadSettingsModel tgDownloadSettings)
{
Channel? channel = await TgClient.PrepareChannelDownloadMessagesAsync(tgDownloadSettings, true);
if (channel is not null)
TgDownloadSmartSource smartSource = await TgClient.PrepareChannelDownloadMessagesAsync(tgDownloadSettings, true);
if (smartSource.Channel is not null)
{
await TgClient.SetChannelMessageIdFirstAsync(tgDownloadSettings, channel);
await TgClient.SetChannelMessageIdFirstAsync(tgDownloadSettings, smartSource.Channel);
LoadTgClientSettings(tgDownloadSettings, true, false);
return;
}

ChatBase? chatBase = await TgClient.PrepareChatBaseDownloadMessagesAsync(tgDownloadSettings, true);
if (chatBase is not null)
smartSource = await TgClient.PrepareChatBaseDownloadMessagesAsync(tgDownloadSettings, true);
if (smartSource.ChatBase is not null)
{
await TgClient.SetChannelMessageIdFirstAsync(tgDownloadSettings, chatBase);
await TgClient.SetChannelMessageIdFirstAsync(tgDownloadSettings, smartSource.ChatBase);
LoadTgClientSettings(tgDownloadSettings, true, false);
}
}
Expand Down Expand Up @@ -218,7 +220,8 @@ private void LoadTgClientSettings(TgDownloadSettingsModel tgDownloadSettings, bo
private async Task ManualDownloadAsync(TgDownloadSettingsModel tgDownloadSettings)
{
ShowTableDownload(tgDownloadSettings);
await TgClient.DownloadAllDataAsync(tgDownloadSettings);
await TgClient.DownloadAllDataAsync(tgDownloadSettings);
// Don't move up.
await UpdateSourceWithSettings(tgDownloadSettings);
}

Expand Down
4 changes: 2 additions & 2 deletions Clients/TgDownloaderConsole/TgDownloaderConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.2.550.0</Version>
<Version>0.2.570.0</Version>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
Expand Down Expand Up @@ -59,7 +59,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="WTelegramClient" Version="3.5.8" />
<PackageReference Include="WTelegramClient" Version="3.5.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\TgDownloader\TgDownloader.csproj" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
9 changes: 5 additions & 4 deletions Clients/TgDownloaderWinDesktop/TgDownloaderWinDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>applicationIcon.ico</ApplicationIcon>
<ApplicationIcon>TgDownloaderAppIcon01.ico</ApplicationIcon>
<Platforms>AnyCPU;x64;x86</Platforms>
<Version>0.2.550.0</Version>
<Version>0.2.570.0</Version>
</PropertyGroup>
<ItemGroup>
<Content Include="applicationIcon.ico" />
<Content Include="TgDownloaderAppIcon01.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" PrivateAssets="All" />
<PackageReference Include="WPF-UI" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="WTelegramClient" Version="3.5.8" />
<PackageReference Include="WTelegramClient" Version="3.5.9" />
</ItemGroup>
<ItemGroup>
<None Remove="Assets\applicationIcon-1024.png" />
<None Remove="Assets\applicationIcon-256.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\applicationIcon-01-1024.png" />
<Resource Include="Assets\applicationIcon-1024.png" />
<Resource Include="Assets\applicationIcon-256.png" />
</ItemGroup>
Expand Down
29 changes: 21 additions & 8 deletions Clients/TgDownloaderWinDesktop/ViewModels/TgClientViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

using System.Linq;

namespace TgDownloaderWinDesktop.ViewModels;

[DebuggerDisplay("{ToDebugString()}")]
Expand All @@ -10,7 +12,7 @@ public sealed partial class TgClientViewModel : TgPageViewModelBase, INavigation

public TgMvvmAppModel AppVm { get; }
public TgSqlTableProxyViewModel ProxyVm { get; set; }
public ObservableCollection<TgSqlTableProxyViewModel> ProxiesVms { get; }
public ObservableCollection<TgSqlTableProxyViewModel> ProxiesVms { get; private set; }

public string FirstName { get; set; }
public string LastName { get; set; }
Expand Down Expand Up @@ -90,7 +92,7 @@ public TgClientViewModel()

public void OnNavigatedTo()
{
_ = Task.Run(InitializeViewModelAsync).ConfigureAwait(true);
InitializeViewModelAsync().GetAwaiter();
}

public void OnNavigatedFrom() { }
Expand All @@ -107,22 +109,26 @@ public async Task LoadProxiesForClientAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
ProxiesVms.Clear();
ProxiesVms.Add(new(await ContextManager.ProxyRepository.GetNewAsync()));
await Task.Delay(TimeSpan.FromMilliseconds(1));
TgSqlTableProxyModel proxyNew = await ContextManager.ProxyRepository.GetAsync(AppVm.App.ProxyUid);
ProxiesVms = new();
foreach (TgSqlTableProxyModel proxy in ContextManager.ProxyRepository.GetEnumerable())
{
ProxiesVms.Add(new(proxy));
}

ProxyVm.Proxy = await ContextManager.ProxyRepository.GetAsync(AppVm.App.ProxyUid) ??
await ContextManager.ProxyRepository.GetNewAsync();
if (!ProxiesVms.Select(p => p.Proxy.UserName).Contains(proxyNew.UserName))
{
ProxyVm = new(proxyNew);
ProxiesVms.Add(ProxyVm);
}
}, false);
}

public async Task AfterClientConnectAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
//TgDesktopUtils.TgClient.UpdateStateConnect(TgDesktopUtils.TgClient.IsReady
// ? TgDesktopUtils.TgLocale.MenuClientIsConnected : TgDesktopUtils.TgLocale.MenuClientIsDisconnected);
IsFileSession = TgAppSettings.AppXml.IsExistsFileSession;
Expand All @@ -134,7 +140,8 @@ await TgDesktopUtils.RunFuncAsync(this, async () =>

public string? GetClientDesktopConfig(string what)
{
//TgDesktopUtils.TgClient.UpdateStateMessage($"{TgDesktopUtils.TgLocale.MenuClientIsQuery}: {what}");
TgDesktopUtils.TgClient.UpdateStateMessageAsync($"{TgDesktopUtils.TgLocale.MenuClientIsQuery}: {what}").GetAwaiter();

switch (what)
{
case "api_hash":
Expand Down Expand Up @@ -198,6 +205,7 @@ public async Task OnClientConnectAsync(TgSqlTableProxyViewModel? proxyVm = null)

await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
if (!TgSqlUtils.GetValidXpLite(AppVm.App).IsValid)
return;
await TgDesktopUtils.TgClient.ConnectSessionAsync(proxyVm ?? ProxyVm);
Expand All @@ -213,6 +221,7 @@ public async Task OnClientDisconnectAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
TgDesktopUtils.TgClient.Disconnect();
}, false).ConfigureAwait(false);
}
Expand All @@ -223,6 +232,7 @@ public async Task OnAppSaveAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
await ContextManager.AppRepository.DeleteAllItemsAsync();
await ContextManager.AppRepository.SaveAsync(AppVm.App);
}, false).ConfigureAwait(false);
Expand All @@ -234,6 +244,7 @@ public async Task OnAppClearAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
AppVm.App = await ContextManager.AppRepository.GetNewAsync();
}, false).ConfigureAwait(true);
}
Expand All @@ -244,6 +255,7 @@ public async Task OnAppLoadAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
AppVm.App = await ContextManager.AppRepository.GetFirstAsync();
}, false).ConfigureAwait(false);
}
Expand All @@ -254,6 +266,7 @@ public async Task OnAppEmptyAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
await ContextManager.AppRepository.DeleteAllItemsAsync();
}, false).ConfigureAwait(true);

Expand Down
28 changes: 23 additions & 5 deletions Clients/TgDownloaderWinDesktop/ViewModels/TgDashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ namespace TgDownloaderWinDesktop.ViewModels;
[DebuggerDisplay("{ToDebugString()}")]
public sealed partial class TgDashboardViewModel : TgPageViewModelBase, INavigationAware
{
#region Public and private methods
#region Public and private fields, properties, constructor

public void OnNavigatedTo()
public static string AppVersionTitle { get; set; } = string.Empty;
public static string AppVersionShort { get; set; } = string.Empty;
public static string AppVersionFull { get; set; } = string.Empty;

#endregion

#region Public and private methods

public TgDashboardViewModel()
{
AppVersionTitle = $"{TgDesktopUtils.TgLocale.AppTitleWinDesktop} " +
$"v{TgCommonUtils.GetTrimVersion(Assembly.GetExecutingAssembly().GetName().Version)}";
AppVersionShort = $"v{TgCommonUtils.GetTrimVersion(Assembly.GetExecutingAssembly().GetName().Version)}";
AppVersionFull = $"{TgDesktopUtils.TgLocale.AppVersion}: {AppVersionShort}";
}

public void OnNavigatedTo()
{
_ = Task.Run(InitializeViewModelAsync).ConfigureAwait(true);
InitializeViewModelAsync().GetAwaiter();
}

public void OnNavigatedFrom() { }
Expand All @@ -23,8 +39,9 @@ public void OnNavigatedFrom() { }
[RelayCommand]
public async Task OnSettingsDefaultAsync()
{
await TgDesktopUtils.RunActionAsync(this, () =>
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
TgAppSettings.DefaultXmlSettings();
}, false).ConfigureAwait(false);
}
Expand All @@ -33,8 +50,9 @@ await TgDesktopUtils.RunActionAsync(this, () =>
[RelayCommand]
public async Task OnSettingsSaveAsync()
{
await TgDesktopUtils.RunActionAsync(this, () =>
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
TgAppSettings.StoreXmlSettingsUnsafe();
TgAppSettings.LoadXmlSettings();
}, false).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ public sealed partial class TgFiltersViewModel : TgPageViewModelBase, INavigatio
{
#region Public and private fields, properties, constructor

public TgFiltersViewModel()
{
//
}
public TgFiltersViewModel() { }

#endregion

#region Public and private methods

public void OnNavigatedTo()
{
_ = Task.Run(InitializeViewModelAsync).ConfigureAwait(true);
InitializeViewModelAsync().GetAwaiter();
}

public void OnNavigatedFrom() { }
public void OnNavigatedFrom() { }

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public TgItemProxyViewModel()

public void OnNavigatedTo()
{
_ = Task.Run(InitializeViewModelAsync).ConfigureAwait(true);
InitializeViewModelAsync().GetAwaiter();
}

public void OnNavigatedFrom() { }
Expand Down Expand Up @@ -52,11 +52,12 @@ public async Task OnGetProxyFromStorageAsync()
{
await TgDesktopUtils.RunFuncAsync(ViewModel ?? this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
if (ItemProxyVm.ProxyUid != Guid.Empty)
ProxyUid = ItemProxyVm.ProxyUid;
TgSqlTableProxyModel proxy = await ContextManager.ProxyRepository.GetAsync(ProxyUid);
SetItemProxyVm(proxy, proxy.Uid);
}, true).ConfigureAwait(true);
}, true);
}

// ClearViewCommand
Expand All @@ -65,10 +66,11 @@ public async Task OnClearViewAsync()
{
await TgDesktopUtils.RunFuncAsync(ViewModel ?? this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
if (ItemProxyVm.ProxyUid != Guid.Empty)
ProxyUid = ItemProxyVm.ProxyUid;
ItemProxyVm.Proxy = await ContextManager.ProxyRepository.GetNewAsync();
}, false).ConfigureAwait(true);
}, false);
}

// SaveProxyCommand
Expand All @@ -77,8 +79,9 @@ public async Task OnSaveProxyAsync()
{
await TgDesktopUtils.RunFuncAsync(ViewModel ?? this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
await ContextManager.ProxyRepository.SaveAsync(ItemProxyVm.Proxy, true);
}, false).ConfigureAwait(false);
}, false);
}

// ReturnToSectionProxiesCommand
Expand All @@ -87,12 +90,13 @@ public async Task OnReturnToSectionProxiesAsync()
{
await TgDesktopUtils.RunFuncAsync(this, async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
if (Application.Current.MainWindow is MainWindow navigationWindow)
{
navigationWindow.ShowWindow();
navigationWindow.Navigate(typeof(TgProxiesPage));
}
}, false).ConfigureAwait(false);
}, false);
}

#endregion
Expand Down
Loading

0 comments on commit 33cca40

Please sign in to comment.