Skip to content

Commit

Permalink
Merge pull request #108 from DavidDeSimone/rclone-reset
Browse files Browse the repository at this point in the history
Give developer option to reset an rclone config
  • Loading branch information
DavidDeSimone authored May 1, 2023
2 parents ba83312 + 99371ca commit 429a56f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 19 deletions.
18 changes: 13 additions & 5 deletions core/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const ToplevelCloudFolder = "opencloudsaves/"
// Used for debugging
const printCommands = true

type Storage interface {
GetName() string
GetCreationCommand(ctx context.Context) *exec.Cmd
}

type CloudManager struct {
}

Expand Down Expand Up @@ -82,6 +77,19 @@ func (cm *CloudManager) CreateDriveIfNotExists(ctx context.Context, storage Stor
return nil
}

func (cm *CloudManager) DeleteStorageDrive(ctx context.Context, storage Storage) error {
cmd := makeCommand(ctx, getCloudApp(), "config", "delete", storage.GetName())
var stderr strings.Builder
cmd.Stderr = &stderr

err := cmd.Run()
if err != nil {
return fmt.Errorf(stderr.String())
}

return nil
}

func (cm *CloudManager) ContainsStorageDrive(ctx context.Context, storage Storage) bool {
cmd := makeCommand(ctx, getCloudApp(), "config", "dump")
stdout, err := cmd.Output()
Expand Down
9 changes: 9 additions & 0 deletions core/cloud_perfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,12 @@ func UpdateCloudProvider(cloud int) error {
func CommitCloudPerfs(cloudperfs *CloudPerfs) error {
return writeCloudPerfs(cloudperfs)
}

func DeleteCloudPerfs() error {
path, err := getCloudPath()
if err != nil {
return err
}

return os.Remove(path)
}
22 changes: 22 additions & 0 deletions core/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package core

import (
"context"
"os/exec"
)

type Storage interface {
GetName() string
GetCreationCommand(ctx context.Context) *exec.Cmd
}

func GetAllStorageProviders() []Storage {
return []Storage{
GetGoogleDriveStorage(),
GetDropBoxStorage(),
GetOneDriveStorage(),
GetBoxStorage(),
GetFtpDriveStorage(),
GetNextCloudStorage(),
}
}
57 changes: 44 additions & 13 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ func createDrive(ctx context.Context, cm *core.CloudManager, storage core.Storag
}
}

func deleteAllDrives(ctx context.Context, cm *core.CloudManager) error {
drives := core.GetAllStorageProviders()
for _, drive := range drives {
err := cm.DeleteStorageDrive(ctx, drive)
if err != nil {
return err
}
}
return nil
}

func commitDeleteAllDrives() {
cm := core.MakeCloudManager()
w := GetRootWindow()

go func() {
deleteAllDrives(context.Background(), cm)
core.DeleteCloudPerfs()
w.Dispatch(func() {
w.Eval("OnDeleteAllDrivesComplete()")
})
}()
}

func commitCloudService(service int) error {
cloudperfs := core.GetCurrentCloudPerfsOrDefault()
cloudperfs.Cloud = service
Expand Down Expand Up @@ -529,6 +553,10 @@ func bindFunctions(w webview.WebView) {
})
w.Bind("isCloudSelectionComplete", isCloudSelectionComplete)
w.Bind("convertGameRecordToGameDef", convertGameRecordToGameDef)
w.Bind("commitDeleteAllDrives", commitDeleteAllDrives)
w.Bind("initializeGui", func() {
initializeGui(w, core.MakeDefaultGameDefManager())
})
}

func DirSize(path string) (int64, error) {
Expand Down Expand Up @@ -714,6 +742,21 @@ func refreshMainContent(w webview.WebView) error {
return nil
}

func initializeGui(w webview.WebView, dm core.GameDefManager) {
storage := core.GetCurrentStorageProvider()
if storage == nil {
err := setCloudSelectScreen(w)
if err != nil {
log.Fatal(err)
}
} else {
err := showDefinitionSyncScreen(dm)
if err != nil {
log.Fatal(err)
}
}
}

func setCloudSelectScreen(w webview.WebView) error {
htmlbytes, err := fs.ReadFile(html, "html/selectcloud.html")
if err != nil {
Expand Down Expand Up @@ -743,19 +786,7 @@ func GuiMain(ops *core.Options, dm core.GameDefManager) {
w.SetTitle("Open Cloud Save")
w.SetSize(800, 600, 0)
bindFunctions(w)

storage := core.GetCurrentStorageProvider()
if storage == nil {
err := setCloudSelectScreen(w)
if err != nil {
log.Fatal(err)
}
} else {
err := showDefinitionSyncScreen(dm)
if err != nil {
log.Fatal(err)
}
}
initializeGui(w, dm)

defer (func() {
// This may not work on macOS due to a combination of issues
Expand Down
1 change: 1 addition & 0 deletions gui/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ <h1>Add a game</h1>
<hr>
<div class="danger-zone">DANGER ZONE (Developer Options)</div>
<button class="contentbutton clearsettingsbutton" onclick="onClearUserSettings()">Reset Game Definitions</button>
<button class="contentbutton clearsettingsbutton" onclick="onDeleteAllDrivesClicked()">Reset RClone Config</button>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion gui/html/selectcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function cloudSelected(cloudService) {
log(`Error setting up cloud ${e}`);
});
if (result) {
refresh();
initializeGui();
} else {
setTimeout(poll, timer);

Expand Down
13 changes: 13 additions & 0 deletions gui/html/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ async function onNoticeClicked() {
async function onNoticeClosed() {
const noticeModal = document.getElementById('notice-modal');
noticeModal.style.display = 'none';
}

async function onDeleteAllDrivesClicked() {
window.OnDeleteAllDrivesComplete = () => {
initializeGui();
};

makeConfirmationPopup({
title: "Reset RClone config",
subtitle: "Are you sure you want to reset your rclone config for OpenCloudSave? This will only reset the cloud config's that OpenCloudSave defined. Your save data will not be affected",
onConfirm: async () => {
await commitDeleteAllDrives();
}
})
}

0 comments on commit 429a56f

Please sign in to comment.