Skip to content

Commit

Permalink
have a unified position in appdata for all storage
Browse files Browse the repository at this point in the history
  • Loading branch information
firefly2442 committed Aug 10, 2012
1 parent ddea3cf commit 6a7120c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Arma2NETMySQLPlugin/Databases.cs
Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions Arma2NETMySQLPlugin/Logger.cs
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions Arma2NETMySQLPlugin/SQLite.cs
Expand Up @@ -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);
}
}

Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions Arma2NETMySQLPlugin/Startup.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using Arma2Net.AddInProxy;
using System.IO;

namespace Arma2NETMySQLPlugin
{
Expand All @@ -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();

Expand Down

0 comments on commit 6a7120c

Please sign in to comment.