-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP detection of needing to migrate, need for first time user popup
- Loading branch information
Showing
5 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package migration | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
type migration struct { | ||
smm2Dir string | ||
} | ||
|
||
var Migration *migration | ||
|
||
func Init() error { | ||
if Migration == nil { | ||
dir, err := os.UserConfigDir() | ||
if err != nil { | ||
return fmt.Errorf("failed to get user home directory for migration check: %w", err) | ||
} | ||
Migration = &migration{} | ||
Migration.smm2Dir = dir + "\\SatisfactoryModManager\\profiles\\" | ||
} | ||
return nil | ||
} | ||
|
||
const migrationSuccessMarkerFile = ".smm3_migration_success" | ||
|
||
// https://stackoverflow.com/questions/12518876/how-to-check-if-a-file-exists-in-go | ||
func pathExists(path string) bool { | ||
if _, err := os.Stat(path); err == nil { | ||
return true | ||
} else if errors.Is(err, os.ErrNotExist) { | ||
return false | ||
} else { | ||
slog.Warn("Error when checking path exists, so assuming it does not exist: "+path, slog.Any("error", err)) | ||
return false | ||
} | ||
} | ||
|
||
func (m *migration) NeedsSmm2Migration() bool { | ||
if pathExists(m.smm2Dir) { | ||
return !pathExists(m.smm2Dir + migrationSuccessMarkerFile) | ||
} | ||
return false | ||
} | ||
|
||
func (m *migration) MarkSmm2MigrationSuccess() error { | ||
file, err := os.Create(m.smm2Dir + migrationSuccessMarkerFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to create migration success marker file: %w", err) | ||
} | ||
return file.Close() | ||
Check failure on line 54 in backend/migration/migration.go GitHub Actions / lint-backend (ubuntu-latest)
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters