Skip to content

Commit

Permalink
look in the Arma2 root folder for relevant files and folders first be…
Browse files Browse the repository at this point in the history
…fore looking in AppData

Fixes issue #7
  • Loading branch information
firefly2442 committed Nov 4, 2012
1 parent 4c8b65b commit 04e0f74
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 21 deletions.
15 changes: 11 additions & 4 deletions Arma2NETMySQLPlugin/Databases.cs
Expand Up @@ -16,11 +16,18 @@ public Databases()

//Load the database names, ip, port, usernames, passwords, and so on from file
string line;
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?");
string databasesFileLocation = null;
//check the Arma2 root directory first
if (File.Exists("Databases.txt")) {
databasesFileLocation = Path.GetFullPath("Databases.txt");
} else {
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 in AppData, are you sure it's there?");
}
}
Logger.addMessage(Logger.LogType.Info, "Databases.txt file loading in from: " + databasesFileLocation);

StreamReader sr = File.OpenText(databasesFileLocation);
line = sr.ReadLine();
Expand Down
22 changes: 19 additions & 3 deletions Arma2NETMySQLPlugin/Logger.cs
Expand Up @@ -27,15 +27,26 @@ public enum LogType
private static FileStream fs = null;
private static StreamWriter sw = null;

private static string logDir = null;

public Logger()
{
//Constructor
if (State == loggerState.Stopped)
{
//check to see if the logs folder exists, if not create it
var logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/logs/");
if (!System.IO.Directory.Exists(logDir)) {
System.IO.Directory.CreateDirectory(logDir);
//check the Arma2 root directory first
if (System.IO.Directory.Exists("logs"))
{
logDir = Path.GetFullPath("logs/");
}
else
{
logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/logs/");
if (!System.IO.Directory.Exists(logDir))
{
System.IO.Directory.CreateDirectory(logDir);
}
}

//Setup file streams
Expand All @@ -49,6 +60,11 @@ public Logger()
}
}

public static string getLogDir()
{
return logDir;
}

public static void addMessage(LogType type, string message)
{
if (State == loggerState.Started)
Expand Down
17 changes: 14 additions & 3 deletions Arma2NETMySQLPlugin/SQLite.cs
Expand Up @@ -11,15 +11,25 @@ namespace Arma2NETMySQLPlugin
public class SQLite : SQL
{
private SQLiteConnection sqlite_connection;
private string sqliteDatabaseLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/sqlite/");
private string sqliteDatabaseLocation = null;

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(sqliteDatabaseLocation)) {
System.IO.Directory.CreateDirectory(sqliteDatabaseLocation);
//check the Arma2 root directory first
if (System.IO.Directory.Exists("sqlite"))
{
sqliteDatabaseLocation = Path.GetFullPath("sqlite/");
}
else
{
sqliteDatabaseLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2MySQL/sqlite/");
if (!System.IO.Directory.Exists(sqliteDatabaseLocation))
{
System.IO.Directory.CreateDirectory(sqliteDatabaseLocation);
}
}
}

Expand All @@ -30,6 +40,7 @@ public override void OpenConnection(string databasename)
// if there is no connection
if (sqlite_connection == null)
{
Logger.addMessage(Logger.LogType.Info, "SQLite folder location: " + sqliteDatabaseLocation);
sqlite_connection = new SQLiteConnection("Data Source=" + sqliteDatabaseLocation + databasename + ".sqlite");
}

Expand Down
1 change: 1 addition & 0 deletions Arma2NETMySQLPlugin/Startup.cs
Expand Up @@ -25,6 +25,7 @@ public static void StartupConnection()

//Start up logging
logger_object = new Logger();
Logger.addMessage(Logger.LogType.Info, "Logging started in directory: " + Logger.getLogDir());

Logger.addMessage(Logger.LogType.Info, "Arma2NETMySQL Plugin Started.");

Expand Down
32 changes: 21 additions & 11 deletions ReadMe.html
Expand Up @@ -82,13 +82,26 @@ <h2>Contents</h2>

<a name="howto"><h2>How To Use Arma2NETMySQL</h2></a>

<p>Arma2NETMySQL keeps all files, folders, and sqlite databases that it needs in one location in appdata. The file
structure should match the following (note that you will need to create these folders if they don't exist):</p>
<p>Arma2NETMySQL looks two places for the relevant files and folders. First, it checks the Arma2 root directory. If it can't find
them there, it looks in the AppData folder. I would recommend using the AppData location is possible. This makes future upgrades
and changes easier to manage. However, some people on limited rental servers may need to put them in the root Arma2 folder.
Make sure the file/folder structure matches one of these:</p>

<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\Databases.txt</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\sqlite\</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\logs\</pre>
<ul>
<li>
<pre>This is just an example location, you'll have to figure out where your Arma2 folder is.</pre>
<pre>E:\Program Files\Steam\steamapps\common\arma 2 operation arrowhead\</pre>
<pre>E:\Program Files\Steam\steamapps\common\arma 2 operation arrowhead\Databases.txt</pre>
<pre>E:\Program Files\Steam\steamapps\common\arma 2 operation arrowhead\sqlite\</pre>
<pre>E:\Program Files\Steam\steamapps\common\arma 2 operation arrowhead\logs\</pre>
</li>
<li>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\Databases.txt</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\sqlite\</pre>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\logs\</pre>
</li>
</ul>

<p>This location is for Windows 7/Vista, if you're running an older version, this location will probably be different.</p>

Expand All @@ -102,9 +115,7 @@ <h2>Contents</h2>
We will not be responsible if something gets deleted! Please note that there
are no checks for <a href="https://en.wikipedia.org/wiki/SQL_injection">SQL injection</a> attacks so be extremely
careful about how you allow users to input information that will run against the database.</li>
<li>Put the Databases.txt file in the appdata Arma2MySQL folder:
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\Databases.txt</pre>
</li>
<li>Put the Databases.txt file in the appropriate location (see above notes).</li>
</ul>
<li>There are two ways to run MySQL queries with this plugin. One is using MySQL stored procedures and the other
is just to use straight queries.</li>
Expand Down Expand Up @@ -144,8 +155,7 @@ <h2>Contents</h2>
<ol>
<li>Setup database:</li>
<ul>
<li>Databases need to be in your appdata sqlite folder:</li>
<pre>C:\Users\Yourname\AppData\Local\Arma2MySQL\sqlite\</pre>
<li>Databases need to be in your root Arma2 folder or the appdata sqlite folder (see above notes).</li>
<li>And they need to have the following filename ending:</li>
<pre>.sqlite</pre>
<li>So, for example you might have:</li>
Expand Down

0 comments on commit 04e0f74

Please sign in to comment.