Skip to content

feat: Allow Uploading/Importing Game Settings data to/from Database - #893

Open
bagusnl wants to merge 11 commits into
mainfrom
feat/db-gamesettings-upload
Open

feat: Allow Uploading/Importing Game Settings data to/from Database#893
bagusnl wants to merge 11 commits into
mainfrom
feat/db-gamesettings-upload

Conversation

@bagusnl

@bagusnl bagusnl commented Jul 13, 2026

Copy link
Copy Markdown
Member

Main Goal

Allowing user to synchronize game settings data including:

  • Game settings
  • Collapse game/region specific settings
  • Collapse playtime data

The data gets uploaded to database server that user sets in app settings

PR Status :

  • Overall Status : In Progress
  • Commits : In Progress
  • Synced to base (Collapse:main) : Not yet (pending build failure fix)
  • Build status : OK
  • Crashing : No
  • Bug found caused by PR : 0

Templates

Changelog Prefixes
  **[New]**
  **[Imp]**
  **[Fix]**
  **[Loc]**
  **[Doc]**

@bagusnl
bagusnl requested a review from a team July 13, 2026 07:56
@bagusnl bagusnl self-assigned this Jul 13, 2026
@bagusnl
bagusnl marked this pull request as ready for review August 16, 2026 23:16
Comment on lines +211 to +215
try
{
if (!DbHandler.IsEnabled ?? false)
{
SetApplyTextStatus("Lang._GameSettingsPage.SettingsDBNotSetup", true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Guard clauses in OnRegistryDbUploadButtonClick and OnRegistryDbDownloadButtonClick are missing return statements, causing execution to continue after detecting an error, potentially showing a false success message.
Severity: HIGH

Suggested Fix

Add a return; statement inside the if blocks after calling SetApplyTextStatus in both OnRegistryDbUploadButtonClick and OnRegistryDbDownloadButtonClick to halt execution when the database is not properly configured.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/GameSettingsPageBase.cs#L211-L215

Potential issue: In `OnRegistryDbUploadButtonClick` and
`OnRegistryDbDownloadButtonClick`, the guard clauses that check if the database is
enabled and initialized are missing `return` statements. When a check fails, an error
message is set, but execution continues. This can lead to an operation being attempted
on an unready database, and the initial error message may be overwritten with a success
message, misleading the user into believing the operation was successful when it was
not.

Also affects:

  • CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/GameSettingsPageBase.cs:247~251

Did we get this right? 👍 / 👎 to inform future reviews.

{
string path = Path.GetTempFileName();
_ = await ExportSettings(false, null, null, path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: In PushToDatabase, the exception returned by ExportSettings is discarded, which can lead to uploading corrupt or incomplete data to the database if the export fails.
Severity: HIGH

Suggested Fix

Check the return value of await ExportSettings(...). If it is not null, handle the exception by logging it and preventing the subsequent code from uploading the corrupt temporary file.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
CollapseLauncher/Classes/GameManagement/GameSettings/BaseClass/ImportExportBase.cs#L554

Potential issue: The `PushToDatabase` method calls `ExportSettings` but discards its
return value using `_ = await ExportSettings(...)`. Since `ExportSettings` returns an
`Exception` object on failure instead of throwing, any error during the export process
is silently ignored. If an error occurs after a temporary file has been partially
written, the subsequent validation checks (file existence and non-zero size) will pass.
This results in corrupt or incomplete data being uploaded to the database, which will
cause failures when the user later attempts to download and import these settings.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +581 to +582
string path = Path.GetTempFileName();
await File.WriteAllBytesAsync(path, Convert.FromHexString(retval));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: In GetFromDatabase, an empty string returned from a database query is not handled, causing an exception and leaving an orphaned temporary file on disk.
Severity: MEDIUM

Suggested Fix

In GetFromDatabase, add a check for string.IsNullOrEmpty(retval) after the existing null check to handle cases where the database returns no data, and return early to prevent the exception and file leak.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
CollapseLauncher/Classes/GameManagement/GameSettings/BaseClass/ImportExportBase.cs#L581-L582

Potential issue: In `GetFromDatabase`, if a database query for a blob via
`DbHandler.QueryKey` returns an empty result or a blob in an unexpected format, the
method returns an empty string `""` instead of `null`. The existing check `if (retval ==
null)` does not catch this case. The empty string is then converted to a zero-byte array
and written to a temporary file. When `ImportSettings` attempts to read this empty file,
it throws a `FormatException`. This exception is caught, but the zero-byte temporary
file is not deleted, leading to a file leak on the user's disk.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants