Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
// Creator.cpp : main project file.
2
 
3
#include "stdafx.h"
4
#include "Forms/Form1.h"
5
 
6
using namespace Creator;
7
using namespace System::IO;
8
 
9
[STAThreadAttribute]
10
int main(array<System::String ^> ^args)
11
{
12
	System::String ^temp = IO::Path::GetTempPath();
13
 
14
	Threading::Mutex ^mutex = nullptr;
15
	try {
109 cycrow 16
		bool autoClose = Form1::CheckCommandArguments(args);
17
 
18
		mutex = (autoClose) ? nullptr : gcnew Threading::Mutex(false, "SpkCreator");
19
 
20
		if ( !mutex || mutex->WaitOne(0, false)) 
1 cycrow 21
		{
22
			// Enabling Windows XP visual effects before any controls are created
23
			Application::EnableVisualStyles();
24
			Application::SetCompatibleTextRenderingDefault(false); 
25
 
26
			if ( File::Exists(temp + "\\creator_load.dat") )
27
			{
28
				try { File::Delete(temp + "\\creator_load.dat"); }
29
				catch (System::IO::IOException ^) {}
30
				catch (System::Exception ^) {}
31
			}
32
 
33
			// Create the main window and run it
34
			Application::Run(gcnew Form1(args));
35
		}
36
		else
37
		{
38
			if ( args->Length )
39
			{
40
				if ( File::Exists(temp + "\\creator_load.dat") )
41
				{
42
					StreamWriter ^sw = File::AppendText(temp + "\\creator_load.dat");
43
					try 
44
					{
45
						for ( int i = 0; i < args->Length; i++ )
46
							sw->WriteLine("File: " + args[i]);
47
					}
48
					finally
49
					{
50
						if ( sw )
51
							delete (IDisposable ^)sw;
52
					}
53
				}
54
				else
55
				{
56
					StreamWriter ^sw = File::CreateText(temp + "\\creator_load.dat");
57
					try 
58
					{
59
						for ( int i = 0; i < args->Length; i++ )
60
							sw->WriteLine("File: " + args[i]);
61
					}
62
					finally
63
					{
64
						if ( sw )
65
							delete (IDisposable ^)sw;
66
					}
67
				}
68
 
69
			}
70
			else
71
				MessageBox::Show("There is already another instance of the Package Creator Running", "Already Running", MessageBoxButtons::OK, MessageBoxIcon::Error);
72
		}
73
	}
74
	catch (Threading::AbandonedMutexException ^)
75
	{
76
	}
77
	finally
78
	{
79
		if ( mutex ) mutex->Close();
80
	}
81
 
82
	return 0;
83
}