Skip to content

Commit 40e5e33

Browse files
author
RandomEngy
committed
Updating assembly versions. Changing queue persistence to use SQLite.
1 parent 99c70a3 commit 40e5e33

11 files changed

Lines changed: 127 additions & 59 deletions

File tree

HandBrakeInterop/HandBrakeInterop/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.13.0.0")]
36-
[assembly: AssemblyFileVersion("1.13.0.0")]
35+
[assembly: AssemblyVersion("1.14.0.0")]
36+
[assembly: AssemblyFileVersion("1.14.0.0")]

Installer/VidCoder-x64.iss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[Setup]
55
AppName=VidCoder
6-
AppVerName=VidCoder 0.8.2 (x64)
6+
AppVerName=VidCoder 0.8.3 (x64)
77

88
DefaultDirName={pf}\VidCoder
99
DisableProgramGroupPage=yes
@@ -13,7 +13,7 @@ Compression=lzma
1313
SolidCompression=yes
1414

1515
OutputDir=BuiltInstallers
16-
OutputBaseFilename=VidCoder-0.8.2-x64
16+
OutputBaseFilename=VidCoder-0.8.3-x64
1717

1818
AppId=VidCoder-x64
1919
UsePreviousAppDir=yes

Installer/VidCoder-x86.iss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[Setup]
55
AppName=VidCoder
6-
AppVerName=VidCoder 0.8.2 (x86)
6+
AppVerName=VidCoder 0.8.3 (x86)
77

88
DefaultDirName={pf}\VidCoder
99
DisableProgramGroupPage=yes
@@ -13,7 +13,7 @@ Compression=lzma
1313
SolidCompression=yes
1414

1515
OutputDir=BuiltInstallers
16-
OutputBaseFilename=VidCoder-0.8.2-x86
16+
OutputBaseFilename=VidCoder-0.8.3-x86
1717

1818
AppId=VidCoder
1919
UsePreviousAppDir=yes
@@ -38,10 +38,9 @@ Source: "..\Lib\Ookii.Dialogs.Wpf.dll"; DestDir: "{app}"
3838
Source: "..\Lib\Ookii.Dialogs.Wpf.pdb"; DestDir: "{app}"
3939
Source: "..\Lib\Microsoft.Practices.Unity.dll"; DestDir: "{app}"
4040
Source: "..\Lib\Microsoft.Practices.Unity.Configuration.dll"; DestDir: "{app}"
41-
Source: "..\Lib\System.Data.SQLite.dll"; DestDir: "{app}"
4241
Source: "..\VidCoder\BuiltInPresets.xml"; DestDir: "{app}"
4342
Source: "..\Lib\x86\hb.dll"; DestDir: "{app}"
44-
Source: "..\Lib\x86\SQLite.Interop.dll"; DestDir: "{app}"
43+
Source: "..\Lib\x86\System.Data.SQLite.dll"; DestDir: "{app}"
4544
Source: "..\HandBrakeInterop\HandBrakeInterop\bin\x86\Release\HandBrakeInterop.dll"; DestDir: "{app}"
4645
Source: "..\HandBrakeInterop\HandBrakeInterop\bin\x86\Release\HandBrakeInterop.pdb"; DestDir: "{app}"
4746
Source: "..\License.txt"; DestDir: "{app}"

VidCoder/Model/Database.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static SQLiteConnection CreateConnection()
6565
{
6666
CreateTables(newConnection);
6767

68-
var settingsList = new Dictionary<string, string> {{"Version", "1"}};
68+
var settingsList = new Dictionary<string, string> {{"Version", Utilities.CurrentDatabaseVersion.ToString()}};
6969
AddSettingsList(newConnection, settingsList);
7070
}
7171

VidCoder/Model/DatabaseConfig.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.SQLite;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace VidCoder.Model
9+
{
10+
public static class DatabaseConfig
11+
{
12+
private static Dictionary<string, string> configDefaults;
13+
14+
static DatabaseConfig()
15+
{
16+
configDefaults = new Dictionary<string, string>
17+
{
18+
{"Version", Utilities.CurrentDatabaseVersion.ToString()},
19+
{"EncodeJobs", string.Empty}
20+
};
21+
}
22+
23+
public static string GetConfigString(string configName, SQLiteConnection connection)
24+
{
25+
using (var command = new SQLiteCommand("SELECT value FROM settings WHERE name = '" + configName + "'", connection))
26+
{
27+
using (SQLiteDataReader reader = command.ExecuteReader())
28+
{
29+
if (reader.Read())
30+
{
31+
return reader.GetString(0);
32+
}
33+
}
34+
}
35+
36+
// The setting does not exist in the DB, we need to insert the default value.
37+
38+
if (configDefaults.ContainsKey(configName))
39+
{
40+
AddConfigValue(configName, configDefaults[configName], connection);
41+
42+
return configDefaults[configName];
43+
}
44+
45+
throw new ArgumentException("Config value not found: " + configName, "configName");
46+
}
47+
48+
private static void AddConfigValue(string configName, string configValue, SQLiteConnection connection)
49+
{
50+
using (var settingsInsert = new SQLiteCommand(connection))
51+
{
52+
settingsInsert.CommandText = "INSERT INTO settings (name, value) VALUES (?, ?)";
53+
settingsInsert.Parameters.Add("name", DbType.String).Value = configName;
54+
settingsInsert.Parameters.Add("value", DbType.String).Value = configValue;
55+
56+
settingsInsert.ExecuteNonQuery();
57+
}
58+
}
59+
60+
public static void SetConfigValue(string configName, string configValue, SQLiteConnection connection)
61+
{
62+
var command = new SQLiteCommand("UPDATE settings SET value = ? WHERE name = ?", connection);
63+
command.Parameters.Add("value", DbType.String).Value = configValue;
64+
command.Parameters.Add("name", DbType.String).Value = configName;
65+
66+
if (command.ExecuteNonQuery() == 0)
67+
{
68+
// If the setting did not exist, add it
69+
AddConfigValue(configName, configValue, connection);
70+
}
71+
}
72+
}
73+
}

VidCoder/Model/EncodeJobs.cs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,70 @@ namespace VidCoder.Model
1212
{
1313
public static class EncodeJobsPersist
1414
{
15-
private static readonly string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"VidCoder");
16-
private static readonly string EncodeJobsPath = Path.Combine(DataFolder, @"EncodeJobs.xml");
15+
private static readonly string EncodeJobsPath = Path.Combine(Utilities.AppFolder, "EncodeJobs.xml");
1716
private static XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<EncodeJob>));
1817

1918
public static List<EncodeJob> EncodeJobs
2019
{
2120
get
2221
{
23-
EnsureFolderCreated();
24-
25-
try
22+
if (File.Exists(EncodeJobsPath))
2623
{
2724
XDocument doc = XDocument.Load(EncodeJobsPath);
2825
XElement presetArray = doc.Element("EncodeJobs").Element("ArrayOfEncodeJob");
2926

3027
using (XmlReader reader = presetArray.CreateReader())
3128
{
3229
var presetList = xmlSerializer.Deserialize(reader) as List<EncodeJob>;
30+
File.Delete(EncodeJobsPath);
31+
3332
return presetList;
3433
}
3534
}
36-
catch (FileNotFoundException)
37-
{
38-
return new List<EncodeJob>();
39-
}
35+
36+
return LoadJobsXmlString(DatabaseConfig.GetConfigString("EncodeJobs", Database.Connection));
4037
}
4138

4239
set
4340
{
44-
EnsureFolderCreated();
45-
StringBuilder xmlBuilder = new StringBuilder();
46-
using (XmlWriter writer = XmlWriter.Create(xmlBuilder))
47-
{
48-
xmlSerializer.Serialize(writer, value);
49-
}
50-
51-
XElement element = XElement.Parse(xmlBuilder.ToString());
52-
XDocument doc = new XDocument(
53-
new XElement("EncodeJobs",
54-
new XAttribute("Version", "1"),
55-
element));
41+
DatabaseConfig.SetConfigValue("EncodeJobs", SerializeJobs(value), Database.Connection);
42+
}
43+
}
5644

57-
doc.Save(EncodeJobsPath);
45+
private static string SerializeJobs(List<EncodeJob> jobs)
46+
{
47+
var xmlBuilder = new StringBuilder();
48+
using (XmlWriter writer = XmlWriter.Create(xmlBuilder))
49+
{
50+
xmlSerializer.Serialize(writer, jobs);
5851
}
52+
53+
return xmlBuilder.ToString();
5954
}
6055

61-
private static void EnsureFolderCreated()
56+
private static List<EncodeJob> LoadJobsXmlString(string jobsXml)
6257
{
63-
if (!Directory.Exists(DataFolder))
58+
try
59+
{
60+
using (var stringReader = new StringReader(jobsXml))
61+
{
62+
using (var xmlReader = new XmlTextReader(stringReader))
63+
{
64+
return xmlSerializer.Deserialize(xmlReader) as List<EncodeJob>;
65+
}
66+
}
67+
}
68+
catch (XmlException exception)
6469
{
65-
Directory.CreateDirectory(DataFolder);
70+
System.Windows.MessageBox.Show(
71+
"Could not load encode queue: " +
72+
exception +
73+
Environment.NewLine +
74+
Environment.NewLine +
75+
jobsXml);
6676
}
77+
78+
return new List<EncodeJob>();
6779
}
6880
}
6981
}

VidCoder/Model/Presets.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,5 @@ private static void SaveUserPresetsBackground(object presetXmlListObject)
269269
}
270270
}
271271
}
272-
273-
private static string FindUserPresetPath(string baseName)
274-
{
275-
string cleanName = Utilities.CleanFileName(baseName);
276-
277-
string proposedPresetPath = Path.Combine(UserPresetsFolder, cleanName + ".xml");
278-
279-
if (File.Exists(proposedPresetPath))
280-
{
281-
for (int i = 1; i < 100; i++)
282-
{
283-
proposedPresetPath = Path.Combine(UserPresetsFolder, cleanName + "_" + i + ".xml");
284-
if (!File.Exists(proposedPresetPath))
285-
{
286-
break;
287-
}
288-
}
289-
}
290-
291-
return proposedPresetPath;
292-
}
293272
}
294273
}

VidCoder/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("0.8.2.0")]
55-
[assembly: AssemblyFileVersion("0.8.2.0")]
54+
[assembly: AssemblyVersion("0.8.3.0")]
55+
[assembly: AssemblyFileVersion("0.8.3.0")]

VidCoder/Utilities/Utilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static class Utilities
1717
{
1818
public const string UpdateInfoUrl = "http://engy.us/VidCoder/latest.xml";
1919
public const string AppDataFolderName = "VidCoder";
20+
public const int CurrentDatabaseVersion = 11;
2021

2122
private static List<string> disallowedCharacters = new List<string> { "\\", "/", "\"", ":", "*", "?", "<", ">", "|" };
2223

VidCoder/VidCoder.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
</Reference>
128128
<Reference Include="System.Data.Entity" />
129129
<Reference Include="System.Data.SQLite">
130-
<HintPath>..\Lib\System.Data.SQLite.dll</HintPath>
130+
<HintPath>..\Lib\$(Platform)\System.Data.SQLite.dll</HintPath>
131131
</Reference>
132132
<Reference Include="System.Drawing" />
133133
<Reference Include="System.Management" />
@@ -262,6 +262,7 @@
262262
<Compile Include="DataReaderExtensions.cs" />
263263
<Compile Include="EnumStringConverter.cs" />
264264
<Compile Include="Model\Database.cs" />
265+
<Compile Include="Model\DatabaseConfig.cs" />
265266
<Compile Include="Model\EncodeResult.cs" />
266267
<Compile Include="Model\PreviewImageJob.cs" />
267268
<Compile Include="Model\SaveImageJob.cs" />
@@ -511,6 +512,5 @@
511512
<Target Name="AfterBuild">
512513
<Copy SourceFiles="..\Lib\$(Platform)\hb.dll" DestinationFolder="$(OutDir)" />
513514
<Copy SourceFiles="..\HandBrakeInterop\HandBrakeInterop\bin\$(Platform)\Release\HandBrakeInterop.pdb" DestinationFolder="$(OutDir)" />
514-
<Copy SourceFiles="..\Lib\$(Platform)\SQLite.Interop.dll" DestinationFolder="$(OutDir)" />
515515
</Target>
516516
</Project>

0 commit comments

Comments
 (0)