Subversion Repositories spk

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

// Creator.cpp : main project file.

#include "stdafx.h"
#include "Forms/Form1.h"

using namespace Creator;
using namespace System::IO;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
        System::String ^temp = IO::Path::GetTempPath();

        Threading::Mutex ^mutex = nullptr;
        try {
                mutex = gcnew Threading::Mutex(false, "SpkCreator");
                if ( mutex->WaitOne(0, false)) 
                {
                        // Enabling Windows XP visual effects before any controls are created
                        Application::EnableVisualStyles();
                        Application::SetCompatibleTextRenderingDefault(false); 


                        if ( File::Exists(temp + "\\creator_load.dat") )
                        {
                                try { File::Delete(temp + "\\creator_load.dat"); }
                                catch (System::IO::IOException ^) {}
                                catch (System::Exception ^) {}
                        }

                        // Create the main window and run it
                        Application::Run(gcnew Form1(args));
                }
                else
                {
                        if ( args->Length )
                        {
                                if ( File::Exists(temp + "\\creator_load.dat") )
                                {
                                        StreamWriter ^sw = File::AppendText(temp + "\\creator_load.dat");
                                        try 
                                        {
                                                for ( int i = 0; i < args->Length; i++ )
                                                        sw->WriteLine("File: " + args[i]);
                                        }
                                        finally
                                        {
                                                if ( sw )
                                                        delete (IDisposable ^)sw;
                                        }
                                }
                                else
                                {
                                        StreamWriter ^sw = File::CreateText(temp + "\\creator_load.dat");
                                        try 
                                        {
                                                for ( int i = 0; i < args->Length; i++ )
                                                        sw->WriteLine("File: " + args[i]);
                                        }
                                        finally
                                        {
                                                if ( sw )
                                                        delete (IDisposable ^)sw;
                                        }
                                }

                        }
                        else
                                MessageBox::Show("There is already another instance of the Package Creator Running", "Already Running", MessageBoxButtons::OK, MessageBoxIcon::Error);
                }
        }
        catch (Threading::AbandonedMutexException ^)
        {
        }
        finally
        {
                if ( mutex ) mutex->Close();
        }

        return 0;
}