Skip to content

Commit

Permalink
Additional locations to search for servers.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Jamison committed Nov 9, 2013
1 parent 8a4fc59 commit 8eb9f27
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
6 changes: 5 additions & 1 deletion App.config
Expand Up @@ -7,11 +7,15 @@
</configSections>
<appSettings>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<applicationSettings>
<DBMulticast.Properties.Settings>
<setting name="ServerConfigLocation" serializeAs="String">
<value>.</value>
</setting>
<setting name="ServerConfigFileName" serializeAs="String">
<value>servers.xml</value>
</setting>
</DBMulticast.Properties.Settings>
</applicationSettings>
</configuration>
4 changes: 3 additions & 1 deletion DBMulticast.csproj
Expand Up @@ -161,7 +161,9 @@
<None Include="ScintillaNet.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="SciLexer.dll" />
<Content Include="SciLexer.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SciLexer64.dll" />
<Content Include="ScintillaNET.xml" />
<Content Include="Script.ico" />
Expand Down
35 changes: 34 additions & 1 deletion FormUtility.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -14,11 +15,43 @@ class FormUtility
public static ServerList LoadDatabaseDefinitions()
{
var s = new XmlSerializer(typeof(ServerList));
TextReader r = new StreamReader(Path.Combine(Settings.Default.ServerConfigLocation, "servers.xml"));
TextReader r = new StreamReader(getServersFileLocation());
var loaded = (ServerList)s.Deserialize(r);
r.Close();

return loaded;
}
internal static string getServersFileLocation()
{
return Path.Combine(getServersFilePath(), Settings.Default.ServerConfigFileName);
}
internal static string getServersFilePath()
{
bool found = true;
string serversFileName = Settings.Default.ServerConfigFileName;
string serversFileLocation = Settings.Default.ServerConfigLocation;
if (! File.Exists(Path.Combine(serversFileLocation, serversFileName)))
{
string appDirectory = "DBMulticast\\";
serversFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), appDirectory);
if (! File.Exists(Path.Combine(serversFileLocation, serversFileName)))
{
serversFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), appDirectory);
if (! File.Exists(Path.Combine(serversFileLocation, serversFileName)))
{
serversFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), appDirectory);
if (! File.Exists(Path.Combine(serversFileLocation, serversFileName)))
{
serversFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), appDirectory);
if (!File.Exists(Path.Combine(serversFileLocation, serversFileName)))
found = false;
serversFileLocation = Settings.Default.ServerConfigLocation;
}
}
}
}
Debug.WriteLine("servers.xml location: {0} (found {1})", serversFileLocation, found);
return serversFileLocation;
}
}
}
6 changes: 3 additions & 3 deletions MultiCast.cs
Expand Up @@ -429,7 +429,7 @@ void queryWorker_DoWork(object sender, DoWorkEventArgs e)

private void LoadDatabaseDefinitions()
{
var configFile = Path.Combine(Settings.Default.ServerConfigLocation, "servers.xml");
var configFile = Path.Combine(FormUtility.getServersFileLocation());
EnsureDBDefsExist(configFile);
var s = new XmlSerializer(typeof(ServerList));
using (TextReader r = new StreamReader(configFile))
Expand Down Expand Up @@ -458,8 +458,8 @@ private void SaveDatabaseDefinitions()
{
UpdateServerList();
var s = new XmlSerializer(typeof(ServerList));
File.Copy(Path.Combine(Settings.Default.ServerConfigLocation, "servers.xml"), Path.Combine(Settings.Default.ServerConfigLocation, "servers.xml_backup"), true);
using (TextWriter w = new StreamWriter(Path.Combine(Settings.Default.ServerConfigLocation, "servers.xml")))
File.Copy(FormUtility.getServersFileLocation(), Path.Combine(FormUtility.getServersFilePath(), "servers.xml_backup"), true);
using (TextWriter w = new StreamWriter(FormUtility.getServersFileLocation()))
{
s.Serialize(w, _ServerList);
}
Expand Down
8 changes: 8 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Expand Up @@ -5,5 +5,8 @@
<Setting Name="ServerConfigLocation" Type="System.String" Scope="Application">
<Value Profile="(Default)">.</Value>
</Setting>
<Setting Name="ServerConfigFileName" Type="System.String" Scope="Application">
<Value Profile="(Default)">servers.xml</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 8eb9f27

Please sign in to comment.