Skip to content

Commit

Permalink
适应realm数据库版本
Browse files Browse the repository at this point in the history
  • Loading branch information
Exsper committed Nov 3, 2024
1 parent c67dc71 commit c16641a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
3 changes: 3 additions & 0 deletions LazerFilesViewer/Localisation/Resource.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ May cause database corruption or Lazer exceptions, please use with caution!</val
<data name="String_Create_File_Error" xml:space="preserve">
<value>Failed to create file</value>
</data>
<data name="String_Database_Version_Warning" xml:space="preserve">
<value>The current database version is inconsistent with the software settings version, which may cause issues. If your Lazer version is the latest version, please submit an issue.</value>
</data>
<data name="String_Delete_Error" xml:space="preserve">
<value>Failed to delete.</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions LazerFilesViewer/Localisation/Resource.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
<data name="String_Create_File_Error" xml:space="preserve">
<value>创建文件时发生错误</value>
</data>
<data name="String_Database_Version_Warning" xml:space="preserve">
<value>当前数据库版本与软件设置版本不一致,可能会遇到问题。如lazer版本为最新版本,请提交issue</value>
</data>
<data name="String_Delete_Error" xml:space="preserve">
<value>删除文件失败</value>
</data>
Expand Down
73 changes: 35 additions & 38 deletions LazerFilesViewer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace LazerFilesViewer
{
public partial class MainForm : Form
{
private const int schema_version = 43;
private ulong newest_schema_version = 43;
private ulong schema_version = 43;
private bool shownVersionWarning = false;

private string TempFolder = AppDomain.CurrentDomain.BaseDirectory + "tmp\\";
private string BackupFolder = AppDomain.CurrentDomain.BaseDirectory + "Backups\\";
Expand Down Expand Up @@ -52,9 +54,14 @@ private RealmConfiguration GetConfiguration(bool isReadOnly = true)

private void BuildDirectories()
{

Realm r = Realm.GetInstance(GetConfiguration());

if (!shownVersionWarning && schema_version < newest_schema_version)
{
DialogResult result = MessageBox.Show(Language.GetString("String_Database_Version_Warning"), Language.GetString("String_Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
shownVersionWarning = true;
}

var allSkins = r.All<SkinInfo>();
var allBeatmapSets = r.All<BeatmapSetInfo>();
/*
Expand Down Expand Up @@ -113,6 +120,29 @@ private void BuildDirectories()
AddUpdateAppSettings("DataBasePath", DataBasePath);
}

private void ReadRealm()
{
try
{
BuildDirectories();
}
catch (Exception ex)
{
if (ex.Message.StartsWith("Provided schema version") && schema_version == newest_schema_version)
{
string correctVersion = ex.Message.Split(" ").Last();
correctVersion = correctVersion.Substring(0, correctVersion.Length - 1);
schema_version = ulong.Parse(correctVersion);
if (schema_version != newest_schema_version) { ReadRealm(); return; }
}
DialogResult result = MessageBox.Show(Language.GetString("String_Load_Database_Error") + "\r\n" + ex, Language.GetString("String_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
if (result == DialogResult.OK)
{
Close();
}
}
}

static void AddUpdateAppSettings(string key, string value)
{
try
Expand Down Expand Up @@ -432,18 +462,7 @@ private void MainForm_Load(object sender, EventArgs e)
}
}

try
{
BuildDirectories();
}
catch (Exception ex)
{
DialogResult result = MessageBox.Show(Language.GetString("String_Load_Database_Error") + "\r\n" + ex, Language.GetString("String_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
if (result == DialogResult.OK)
{
Close();
}
}
ReadRealm();

OpenPath("");
}
Expand Down Expand Up @@ -701,18 +720,7 @@ private void Reload(bool reloadDataBase = true)
HistoryPoint? hp = historyControl.GetCurrentHistoryPoint();
if (reloadDataBase)
{
try
{
BuildDirectories();
}
catch (Exception ex)
{
DialogResult result = MessageBox.Show(Language.GetString("String_Load_Database_Error") + "\r\n" + ex, Language.GetString("String_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
if (result == DialogResult.OK)
{
Close();
}
}
ReadRealm();
}
if (hp == null)
{
Expand Down Expand Up @@ -1138,18 +1146,7 @@ private void SetDatabasePathToolStripMenuItem_Click(object sender, EventArgs e)
LazerFilePath = LazerPath + @"files\";
}

try
{
BuildDirectories();
}
catch (Exception ex)
{
DialogResult result = MessageBox.Show(Language.GetString("String_Load_Database_Error") + "\r\n" + ex, Language.GetString("String_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
if (result == DialogResult.OK)
{
Close();
}
}
ReadRealm();

OpenPath("");
}
Expand Down

0 comments on commit c16641a

Please sign in to comment.