Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ private static void AttachEventToNotification(PresetConfig presetConfig, IBackgr
activity!.ProgressChanged += progressChangedEventHandler;
activity!.StatusChanged += statusChangedEventHandler;

// The notification can be attached after the operation has already
// started. Hydrate it immediately instead of waiting for another
// progress/status event and leaving the placeholder text visible.
progressChangedEventHandler(activity, activity.Progress);
statusChangedEventHandler(activity, activity.Status);

activity.FlushingTrigger += (_, _) =>
{
activity.ProgressChanged -= progressChangedEventHandler;
Expand Down
7 changes: 7 additions & 0 deletions CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ protected virtual void UpdateProgressCopyStream(long currentPosition, int read,

protected double CalculateSpeed(long receivedBytes) => CalculateSpeed(receivedBytes, ref _scLastSpeed, ref _scLastReceivedBytes, ref _scLastTick);

protected void ResetSpeedCalculator()
{
Interlocked.Exchange(ref _scLastReceivedBytes, 0);
Interlocked.Exchange(ref _scLastTick, Environment.TickCount64);
_scLastSpeed = 0;
}

protected static double CalculateSpeed(long receivedBytes, ref double lastSpeedToUse, ref long lastReceivedBytesToUse, ref long lastTickToUse)
{
long currentTick = Environment.TickCount64 - lastTickToUse + 1;
Expand Down
2 changes: 2 additions & 0 deletions CollapseLauncher/Classes/Interfaces/IBackgroundActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal interface IBackgroundActivity
event EventHandler<TotalPerFileStatus> StatusChanged;
event EventHandler FlushingTrigger;

TotalPerFileProgress Progress { get; }
TotalPerFileStatus Status { get; }
bool IsRunning { get; }
UIElement ParentUI { get; }
void CancelRoutine();
Expand Down
37 changes: 33 additions & 4 deletions CollapseLauncher/Classes/Plugins/PluginGameInstallWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public override string GamePath
private InstallProgressState _currentInstallState = InstallProgressState.Idle;
private string _lastActivityStatus = string.Empty;
private float _lastLoggedPercentage = -1f;
private bool _resetSpeedBaseline = true;

private PerFileProgressCallbackNative? _perFileProgressDelegate;
private GCHandle _perFileProgressGcHandle;
Expand Down Expand Up @@ -558,7 +559,18 @@ private void UpdateProgressCallback(in InstallProgress delegateProgress)
long downloadedBytes = delegateProgress.DownloadedBytes;
long downloadedBytesTotal = delegateProgress.TotalBytesToDownload;

long readDownload = delegateProgress.DownloadedBytes - _updateProgressProperty.LastDownloaded;
long readDownload = 0;
if (_resetSpeedBaseline)
{
_resetSpeedBaseline = false;
_updateProgressProperty.LastDownloaded = downloadedBytes;
}
else if (downloadedBytes >= _updateProgressProperty.LastDownloaded)
{
readDownload = downloadedBytes - _updateProgressProperty.LastDownloaded;
_updateProgressProperty.LastDownloaded = downloadedBytes;
}

double currentSpeed = CalculateSpeed(readDownload);

Progress.ProgressAllSizeCurrent = downloadedBytes;
Expand Down Expand Up @@ -605,8 +617,6 @@ or InstallProgressState.Verify
: 0;
}

_updateProgressProperty.LastDownloaded = downloadedBytes;

PublishProgressUi(updateProgressBar: true);
}
}
Expand All @@ -623,7 +633,26 @@ private void UpdateStatusCallback(InstallProgressState delegateState)
{
using (_updateStatusLock.EnterScope())
{
_currentInstallState = delegateState;
if (_currentInstallState != delegateState)
{
_currentInstallState = delegateState;
_resetSpeedBaseline = true;
ResetSpeedCalculator();
Progress.ProgressAllSpeed = 0;
}

if (delegateState == InstallProgressState.Completed)
{
Progress.ProgressAllTimeLeft = TimeSpan.Zero;
if (Progress.ProgressPerFileSizeTotal > 0)
{
Progress.ProgressPerFilePercentage = Math.Min(100d,
ConverterTool.ToPercentage(
Progress.ProgressPerFileSizeTotal,
Progress.ProgressPerFileSizeCurrent));
}
}

ApplyActivityStatusFromProperty();
PublishProgressUi(updateProgressBar: true);
}
Expand Down
2 changes: 2 additions & 0 deletions CollapseLauncher/Classes/Plugins/PluginPresetConfigWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class PluginPresetConfigWrapper : PresetConfig, IDisposable
{
public DiscordPresenceExtension.DiscordPresenceContext DiscordPresenceContext { get; }
public GameManagerExtension.RunGameFromGameManagerContext RunGameContext { get; }
public GameSettingsExtension.GameSettingsContext GameSettingsContext { get; }
public readonly PluginInfo PluginInfo;
public readonly IPlugin Plugin;
private readonly IPluginPresetConfig _config;
Expand All @@ -50,6 +51,7 @@ private unsafe PluginPresetConfigWrapper(PluginInfo pluginInfo, IPluginPresetCon
};

DiscordPresenceContext = new DiscordPresenceExtension.DiscordPresenceContext(pluginInfo.Handle, config);
GameSettingsContext = new GameSettingsExtension.GameSettingsContext(pluginInfo.Handle, config);
}

public unsafe GameManagerExtension.RunGameFromGameManagerContext UseToggledGameLaunchContext()
Expand Down
4 changes: 3 additions & 1 deletion CollapseLauncher/XAMLs/MainApp/MainPage.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ void Impl()
GameNameType.StarRail => typeof(StarRailGameSettingsPage),
GameNameType.Genshin => typeof(GenshinGameSettingsPage),
GameNameType.Zenless => typeof(ZenlessGameSettingsPage),
GameNameType.Plugin when presetConfig is PluginPresetConfigWrapper
{ GameSettingsContext.HasPage: true } => typeof(PluginGameSettingsPage),
_ => null
};

NavigationViewItemsContext.GameSettingsPage.Item.Tag = gspPageType;
NavigationViewItemsContext.GameSettingsPage.Item.Visibility = isPluginGame ? Visibility.Collapsed : Visibility.Visible;
NavigationViewItemsContext.GameSettingsPage.Item.Visibility = gspPageType == null ? Visibility.Collapsed : Visibility.Visible;
NavigationViewItemsContext.FileCleanupPage.Item.Visibility = isPluginGame ? Visibility.Collapsed : Visibility.Visible;
}
}
Expand Down
Loading
Loading