Subversion Repositories spk

Rev

Go to most recent revision | Details | 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 {
16
		mutex = gcnew Threading::Mutex(false, "SpkCreator");
17
		if ( mutex->WaitOne(0, false)) 
18
		{
19
			// Enabling Windows XP visual effects before any controls are created
20
			Application::EnableVisualStyles();
21
			Application::SetCompatibleTextRenderingDefault(false); 
22
 
23
 
24
			if ( File::Exists(temp + "\\creator_load.dat") )
25
			{
26
				try { File::Delete(temp + "\\creator_load.dat"); }
27
				catch (System::IO::IOException ^) {}
28
				catch (System::Exception ^) {}
29
			}
30
 
31
			// Create the main window and run it
32
			Application::Run(gcnew Form1(args));
33
		}
34
		else
35
		{
36
			if ( args->Length )
37
			{
38
				if ( File::Exists(temp + "\\creator_load.dat") )
39
				{
40
					StreamWriter ^sw = File::AppendText(temp + "\\creator_load.dat");
41
					try 
42
					{
43
						for ( int i = 0; i < args->Length; i++ )
44
							sw->WriteLine("File: " + args[i]);
45
					}
46
					finally
47
					{
48
						if ( sw )
49
							delete (IDisposable ^)sw;
50
					}
51
				}
52
				else
53
				{
54
					StreamWriter ^sw = File::CreateText(temp + "\\creator_load.dat");
55
					try 
56
					{
57
						for ( int i = 0; i < args->Length; i++ )
58
							sw->WriteLine("File: " + args[i]);
59
					}
60
					finally
61
					{
62
						if ( sw )
63
							delete (IDisposable ^)sw;
64
					}
65
				}
66
 
67
			}
68
			else
69
				MessageBox::Show("There is already another instance of the Package Creator Running", "Already Running", MessageBoxButtons::OK, MessageBoxIcon::Error);
70
		}
71
	}
72
	catch (Threading::AbandonedMutexException ^)
73
	{
74
	}
75
	finally
76
	{
77
		if ( mutex ) mutex->Close();
78
	}
79
 
80
	return 0;
81
}