Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Added option to reset the repo if something goes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgill28 committed Apr 12, 2021
1 parent 8757ad8 commit 7ffcb71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions DeliCounter/Backend/ModRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ private void LoadModCache()
}
}

public void Reset()
{
if (Repo is not null) Repo.Dispose();
if (Directory.Exists(RepoPath)) Directory.Delete(RepoPath, true);
Refresh();
}

/// <summary>
/// Writes the installed mods cache to the game folder
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion DeliCounter/Controls/ModRepositoryStatus.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<TextBlock Padding="8 4 0 0" x:Name="LastUpdateText" TextWrapping="Wrap">
Please wait...
</TextBlock>
<Button x:Name="ButtonRefresh" Content="Refresh" Margin="0 8 0 0" IsEnabled="False" Click="ButtonRefresh_Click" />
<StackPanel Orientation="Horizontal">
<Button x:Name="ButtonRefresh" Content="Refresh" Margin="0 8 0 0" IsEnabled="False" Click="ButtonRefresh_Click" />
<Button x:Name="ButtonReset" Content="Reset repository" Margin="16 8 0 0" IsEnabled="False" Click="ButtonReset_Click" />
</StackPanel>
</StackPanel>
</UserControl>
9 changes: 9 additions & 0 deletions DeliCounter/Controls/ModRepositoryStatus.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ private void Update()
StatusIcon.Foreground = new SolidColorBrush(Colors.Red);
LastUpdateText.Text = ModRepository.Instance.Exception.Message;
StatusText.Text = "Error";
ButtonReset.IsEnabled = true;
break;
case ModRepository.State.CantUpdate:
StatusIcon.Text = "\uF13C";
StatusIcon.Foreground = new SolidColorBrush(Colors.Orange);
LastUpdateText.Text = ModRepository.Instance.Exception.Message;
StatusText.Text = "Offline";
ButtonReset.IsEnabled = true;
break;
case ModRepository.State.UpToDate:
StatusIcon.Text = SegoeGlyphs.Checkmark;
StatusIcon.Foreground = new SolidColorBrush(Colors.Green);
LastUpdateText.Text =
$"Last update: {ModRepository.Instance.Repo.Head.Commits.First().Author.When}";
StatusText.Text = "Up to date!";
ButtonReset.IsEnabled = false;
break;
}
});
Expand All @@ -53,7 +56,13 @@ private void ButtonRefresh_Click(object sender, System.Windows.RoutedEventArgs e
LastUpdateText.Text = "Please wait...";
StatusText.Text = "Fetching data...";
ButtonRefresh.IsEnabled = false;
ButtonReset.IsEnabled = false;
App.RunInBackgroundThread(ModRepository.Instance.Refresh);
}

private void ButtonReset_Click(object sender, System.Windows.RoutedEventArgs e)
{
App.RunInBackgroundThread(ModRepository.Instance.Reset);
}
}
}

0 comments on commit 7ffcb71

Please sign in to comment.