Skip to content

Commit

Permalink
fix updating from old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nstlaurent committed Aug 14, 2022
1 parent 5bb0d62 commit 3ac3a38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
25 changes: 14 additions & 11 deletions DoomLauncher/Adapters/DbDataSourceAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,18 @@ public IEnumerable<ISourcePortData> GetUtilities(bool loadArchived = false) =>
private IEnumerable<ISourcePortData> GetSourcePorts(SourcePortLaunchType type, bool loadArchived)
{
int sqlArchive = loadArchived ? 1 : 0;
DataTable dt = DataAccess.ExecuteSelect($"select * from SourcePorts where LaunchType = {(int)type} and Archived = {sqlArchive} order by Name collate nocase").Tables[0];
DataTable dt;

try
{
dt = DataAccess.ExecuteSelect($"select * from SourcePorts where LaunchType = {(int)type} and Archived = {sqlArchive} order by Name collate nocase").Tables[0];
}
catch
{
// This is for updates before Archived column existed...
dt = DataAccess.ExecuteSelect($"select * from SourcePorts where LaunchType = {(int)type}").Tables[0];
}

List<ISourcePortData> sourcePorts = new List<ISourcePortData>();

foreach (DataRow dr in dt.Rows)
Expand All @@ -324,24 +335,16 @@ private static ISourcePortData CreateSourcePortDataSource(DataTable dt, DataRow
FileOption = (string)CheckDBNull(dr["FileOption"], string.Empty),
ExtraParameters = (string)CheckDBNull(dr["ExtraParameters"], string.Empty),
AltSaveDirectory = new LauncherPath((string)CheckDBNull(dr["AltSaveDirectory"], string.Empty)),
Archived = GetDBObject(dr["Archived"], false,
(object obj) => { return Convert.ToInt32(obj) != 0; })
};

if (dt.Columns.Contains("SettingsFiles"))
sourcePort.SettingsFiles = (string)CheckDBNull(dr["SettingsFiles"], string.Empty);
if (dt.Columns.Contains("Archived"))
sourcePort.Archived = Convert.ToInt32(dr["Archived"]) != 0;

return sourcePort;
}

private static T GetDBObject<T>(object obj, T defaultValue, Func<object, T> convert)
{
if (obj == DBNull.Value)
return defaultValue;

return convert(obj);
}

private static object CheckDBNull(object obj, object defaultValue)
{
if (obj == DBNull.Value)
Expand Down
14 changes: 13 additions & 1 deletion DoomLauncher/Handlers/VersionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,26 @@ private void Pre_Version_3_3_0()

private void Pre_Version_3_3_1()
{

string query = @"update SourcePorts set
SupportedExtensions = @SupportedExtensions
where SourcePortID = @sourcePortID";

var sourcePorts = m_adapter.GetSourcePorts();
foreach (var sourcePort in sourcePorts)
{
if (sourcePort.SupportedExtensions.Contains(".pke"))
continue;

sourcePort.SupportedExtensions += ",.pke";
m_adapter.UpdateSourcePort(sourcePort);

List<DbParameter> parameters = new List<DbParameter>
{
DataAccess.DbAdapter.CreateParameter("SupportedExtensions", sourcePort.SupportedExtensions),
DataAccess.DbAdapter.CreateParameter("sourcePortID", sourcePort.SourcePortID)
};

DataAccess.ExecuteNonQuery(query, parameters);
}
}

Expand Down

0 comments on commit 3ac3a38

Please sign in to comment.