Skip to content

Commit

Permalink
Merge pull request #34 from HazelnutCheese/METIS-21
Browse files Browse the repository at this point in the history
METIS-21 Fix Fresh Install Database Crash
  • Loading branch information
HazelnutCheese authored Sep 7, 2023
2 parents e026872 + 34855c3 commit 63404c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ModEngine2ConfigTool/ModEngine2ConfigTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.3.0</AssemblyVersion>
<FileAssemblyVersion>1.3.0</FileAssemblyVersion>
<Version>1.3.0</Version>
<AssemblyVersion>1.3.1</AssemblyVersion>
<FileAssemblyVersion>1.3.1</FileAssemblyVersion>
<Version>1.3.1</Version>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<ApplicationIcon>Resources\icon_07.ico</ApplicationIcon>
<StartupObject>ModEngine2ConfigTool.EntryPoint</StartupObject>
Expand Down
18 changes: 17 additions & 1 deletion ModEngine2ConfigTool/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ public DatabaseService(string dataStorage)
{
_dataStorage = dataStorage;
_databaseContext = new DatabaseContext(_dataStorage);

_databaseContext.Database.EnsureCreated();
_databaseContext.Database.Migrate();

if(!CheckIfColumnOnTableExists())
{
_databaseContext.Database.Migrate();
}
}

public List<Profile> GetProfiles()
Expand Down Expand Up @@ -311,5 +316,16 @@ private void SortOrdering(Profile profile)
profile.ModsOrder = string.Join(";", profile.Mods.Select(x => x.ModId));
profile.DllsOrder = string.Join(";", profile.Dlls.Select(x => x.DllId));
}

private bool CheckIfColumnOnTableExists()
{
var result = _databaseContext.Database.SqlQuery<string>(
@$"SELECT GROUP_CONCAT(NAME,',') FROM PRAGMA_TABLE_INFO('Profiles')").ToList();

var hasModsOrder = result?.FirstOrDefault()?.Contains("ModsOrder") ?? false;
var hasDllsOrder = result?.FirstOrDefault()?.Contains("DllsOrder") ?? false;

return hasModsOrder && hasDllsOrder;
}
}
}

0 comments on commit 63404c9

Please sign in to comment.