From 6a7120c87aab33f8d075f783bbfea35062b12623 Mon Sep 17 00:00:00 2001 From: firefly2442 Date: Fri, 10 Aug 2012 14:16:37 -0500 Subject: [PATCH] have a unified position in appdata for all storage --- Arma2NETMySQLPlugin/Databases.cs | 5 +++-- Arma2NETMySQLPlugin/Logger.cs | 10 +++++----- Arma2NETMySQLPlugin/SQLite.cs | 9 +++++---- Arma2NETMySQLPlugin/Startup.cs | 8 ++++++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Arma2NETMySQLPlugin/Databases.cs b/Arma2NETMySQLPlugin/Databases.cs index 49015cc..baac760 100644 --- a/Arma2NETMySQLPlugin/Databases.cs +++ b/Arma2NETMySQLPlugin/Databases.cs @@ -16,12 +16,13 @@ public Databases() //Load the database names, ip, port, usernames, passwords, and so on from file string line; - if (!File.Exists("Databases.txt")) + var databasesFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/Databases.txt"); + if (!File.Exists(databasesFileLocation)) { Logger.addMessage(Logger.LogType.Error, "Unable to find the Databases.txt file, are you sure it's there?"); } - StreamReader sr = File.OpenText("Databases.txt"); + StreamReader sr = File.OpenText(databasesFileLocation); line = sr.ReadLine(); while (line != null) { diff --git a/Arma2NETMySQLPlugin/Logger.cs b/Arma2NETMySQLPlugin/Logger.cs index 9c4c1dd..6e0c6ad 100644 --- a/Arma2NETMySQLPlugin/Logger.cs +++ b/Arma2NETMySQLPlugin/Logger.cs @@ -33,16 +33,16 @@ public Logger() if (State == loggerState.Stopped) { //check to see if the logs folder exists, if not create it - if (!System.IO.Directory.Exists("logs")) - { - System.IO.Directory.CreateDirectory("logs"); + var logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/logs/"); + if (!System.IO.Directory.Exists(logDir)) { + System.IO.Directory.CreateDirectory(logDir); } //Setup file streams DateTime dateValue = new DateTime(); dateValue = DateTime.Now; - string relativepath = Path.Combine("logs", dateValue.ToString("MM-dd-yyyy_HH-mm-ss") + ".log"); - fs = new FileStream(relativepath, FileMode.Append); + string fullpath = Path.Combine(logDir, dateValue.ToString("MM-dd-yyyy_HH-mm-ss") + ".log"); + fs = new FileStream(fullpath, FileMode.Append); sw = new StreamWriter(fs); state = loggerState.Started; diff --git a/Arma2NETMySQLPlugin/SQLite.cs b/Arma2NETMySQLPlugin/SQLite.cs index 682b20a..6c5c82f 100644 --- a/Arma2NETMySQLPlugin/SQLite.cs +++ b/Arma2NETMySQLPlugin/SQLite.cs @@ -4,21 +4,22 @@ using System.Text; using System.Data.SQLite; using System.Data; +using System.IO; namespace Arma2NETMySQLPlugin { public class SQLite : SQL { private SQLiteConnection sqlite_connection; + private string sqliteDatabaseLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/sqlite/"); public SQLite() { // Default constructor for the derived class //check to see if the sqlite folder exists, if not create it - if (!System.IO.Directory.Exists("sqlite")) - { - System.IO.Directory.CreateDirectory("sqlite"); + if (!System.IO.Directory.Exists(sqliteDatabaseLocation)) { + System.IO.Directory.CreateDirectory(sqliteDatabaseLocation); } } @@ -29,7 +30,7 @@ public override void OpenConnection(string databasename) // if there is no connection if (sqlite_connection == null) { - sqlite_connection = new SQLiteConnection("Data Source=sqlite/" + databasename + ".sqlite"); + sqlite_connection = new SQLiteConnection("Data Source=" + sqliteDatabaseLocation + databasename + ".sqlite"); } sqlite_connection.Open(); diff --git a/Arma2NETMySQLPlugin/Startup.cs b/Arma2NETMySQLPlugin/Startup.cs index 8bf20a2..5cc32f4 100644 --- a/Arma2NETMySQLPlugin/Startup.cs +++ b/Arma2NETMySQLPlugin/Startup.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using Arma2Net.AddInProxy; +using System.IO; namespace Arma2NETMySQLPlugin { @@ -15,6 +16,13 @@ public static void StartupConnection() { if (started_up == false) { + //create appdata folder if it doesn't already exist + var appDataLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL"); + //check to see if the Arma2MySQL folder exists, if not create it + if (!System.IO.Directory.Exists(appDataLocation)) { + System.IO.Directory.CreateDirectory(appDataLocation); + } + //Start up logging logger_object = new Logger();