Subversion Repositories spk

Rev

Blame | Last modification | View Log | RSS feed

// AutoUpdater.cpp : main project file.

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

using namespace AutoUpdater;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
        // Enabling Windows XP visual effects before any controls are created
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false); 

        if ( args->Length < 1 )
        {
                MessageBox::Show("Invalid Arguments, Missing filename", "Auto Updater", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                return 1;
        }

        System::String ^downloadFile = args[0];
        while ( downloadFile->EndsWith("\r") )
                downloadFile = downloadFile->Substring(0, downloadFile->Length - 1);
        System::String ^runFile;

        if ( args->Length > 1 )
                runFile = args[1];

        // Create the main window and run it
        bool updated = true;
        if ( downloadFile->Contains("|") )
        {
                System::String ^file;
                int pos = 0;

                while ( pos < downloadFile->Length )
                {
                        int start = pos;
                        pos = downloadFile->IndexOf("|", pos);
                        if ( pos == -1 )
                                file = downloadFile->Substring(start);
                        else
                                file = downloadFile->Substring(start, pos - start);
                        
                        int checkPos = file->IndexOf('\r');
                        while ( checkPos != -1 )
                        {
                                file = file->Remove(checkPos, 1);
                                checkPos = file->IndexOf('\r', checkPos);
                        }

                        Form1 ^f = gcnew Form1(file);
                        Application::Run(f);

                        if ( !f->IsUpdated() )
                                updated = false;

                        if ( pos == -1 )
                                break;
                        pos++;
                }
        }
        else
        {
                updated = false;
                Form1 ^f = gcnew Form1(downloadFile);
                Application::Run(f);
                if ( f->IsUpdated() )
                        updated = true;
        }

        if ( updated )
                MessageBox::Show("Plugin Manager has now been updated", "Auto Updater", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

        if ( runFile )
        {
                System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(runFile);
                info->WorkingDirectory = System::IO::FileInfo(runFile).DirectoryName;
                info->UseShellExecute = false;
                info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
                System::Diagnostics::Process ^process = System::Diagnostics::Process::Start(info);
        }

        return 0;
}