Skip to content

Commit

Permalink
check for outdated files
Browse files Browse the repository at this point in the history
  • Loading branch information
Flutterish committed Dec 29, 2021
1 parent 0018eb7 commit 1b2e264
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
24 changes: 23 additions & 1 deletion osu.Game.Rulesets.RurusettoAddon/RulesetDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,34 @@ public void CheckAvailability ( RulesetIdentity ruleset ) {

if ( ruleset.Source == Source.Web ) {
ruleset.RequestDetail().ContinueWith( t => {
if ( !t.IsFaulted && t.Result.CanDownload ) {
if ( t.IsFaulted ) {
availability.Value |= Availability.NotAvailableOnline;
return; // TODO report this
}

if ( t.Result.CanDownload ) {
availability.Value |= Availability.AvailableOnline;
}
else {
availability.Value |= Availability.NotAvailableOnline;
}

if ( ruleset.ListingEntry?.Status is Status s ) {
if ( File.Exists( ruleset.LocalPath ) ) {
var info = new FileInfo( ruleset.LocalPath );
info.Refresh();

if ( s.LatestUpdate.HasValue && info.CreationTimeUtc < s.LatestUpdate.Value ) {
availability.Value |= Availability.Outdated;
}
else if ( info.Length != s.FileSize ) {
availability.Value |= Availability.Outdated;
}
}
else {
availability.Value |= Availability.Outdated;
}
}
} );
}
else {
Expand Down
31 changes: 19 additions & 12 deletions osu.Game.Rulesets.RurusettoAddon/UI/RulesetDownloadButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,18 @@ private void updateVisuals () {
Icon.Alpha = 1;
this.FadeTo( 1f, 200 );
Background.FadeColour( Colour4.FromHex( "#6CB946" ), 200, Easing.InOutExpo );
Icon.Scale = new osuTK.Vector2( 1.7f );
Icon.Icon = FontAwesome.Regular.CheckCircle;
TooltipText = Avail.Value.HasFlagFast( Availability.NotAvailableOnline ) ? "Installed, not available online" : "Installed";
if ( Avail.Value.HasFlagFast( Availability.Outdated ) && Avail.Value.HasFlagFast( Availability.AvailableOnline ) && State.Value == DownloadState.NotDownloading ) {
Icon.Scale = new osuTK.Vector2( 1.5f );
Icon.Icon = FontAwesome.Solid.Download;

TooltipText = "Update";
}
else {
Icon.Scale = new osuTK.Vector2( 1.7f );
Icon.Icon = FontAwesome.Regular.CheckCircle;

TooltipText = Avail.Value.HasFlagFast( Availability.NotAvailableOnline ) ? "Installed, not available online" : "Installed";
}

if ( State.Value == DownloadState.ToBeImported ) {
warning.FadeIn( 200 );
Expand Down Expand Up @@ -156,16 +165,14 @@ private void updateVisuals () {
}

void onClick () {
if ( Avail.Value.HasFlagFast( Availability.AvailableLocally ) && currentRuleset is Bindable<RulesetInfo> current && ruleset.LocalRulesetInfo is RulesetInfo info ) {
current.Value = info;
if ( Avail.Value.HasFlagFast( Availability.AvailableOnline ) && State.Value == DownloadState.NotDownloading && Avail.Value.HasFlagFast( Availability.Outdated ) ) {
DownloadManager.UpdateRuleset( ruleset );
}
else if ( Avail.Value.HasFlagFast( Availability.AvailableOnline ) && State.Value == DownloadState.NotDownloading ) {
if ( Avail.Value.HasFlagFast( Availability.Outdated ) ) {
DownloadManager.UpdateRuleset( ruleset );
}
else if ( Avail.Value.HasFlagFast( Availability.NotAvailableLocally ) ) {
DownloadManager.DownloadRuleset( ruleset );
}
else if ( Avail.Value.HasFlagFast( Availability.AvailableOnline ) && State.Value == DownloadState.NotDownloading && Avail.Value.HasFlagFast( Availability.NotAvailableLocally ) ) {
DownloadManager.DownloadRuleset( ruleset );
}
else if ( Avail.Value.HasFlagFast( Availability.AvailableLocally ) && currentRuleset is Bindable<RulesetInfo> current && ruleset.LocalRulesetInfo is RulesetInfo info ) {
current.Value = info;
}
}

Expand Down

0 comments on commit 1b2e264

Please sign in to comment.