//
// NOLF SWEDISH MAP PACK Update setup.rul
//

// Game & folder names
#define APP_TITLE       "NOLF kart-pack nr. 1 (v1.001)"
#define APP_NAME        "No One Lives Forever"
#define APP_VERSION     "1.0"
#define APP_KEY         "NOLF.exe"
#define DEFAULT_PATH    "Fox\\No One Lives Forever"
#define DEFAULT_GROUP   "Fox Interactive\\No One Lives Forever"
#define UPDATE_VERSION	"1.001"
#define CONTENT_VERSION	"1.001"
#define CONTENT_COMMAND	"-rez Nolfc001.rez"

declare
    NUMBER  nResult;
    NUMBER  nType, nSize;
    STRING  svSrcDir, svTargetDir;
    STRING  svRegKey;
    STRING  svTemp;
    STRING  svVersion;

program
start:
    // Set paths
    svSrcDir     = SRCDIR ^ "..\\..\\";

    // Setup screen & title
    Enable(BACKGROUND);
    SetColor(BACKGROUND, RGB(236, 164, 4));
    SetTitle(APP_TITLE, 26, WHITE);

    SetColor(STATUSBAR, BK_SOLIDBLUE);
    PlaceBitmap(svSrcDir ^ "SETUP\\NOLF1.BMP", 1, CENTERED, CENTERED, CENTERED);
    Delay(2);

    // Get installed path from registry
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    svRegKey = "Software\\Monolith Productions\\" + APP_NAME + "\\" + APP_VERSION;
    nType = REGDB_STRING;
    nSize = -1;
    nResult = RegDBGetKeyValueEx(svRegKey, "WorkingDirectory", nType, svTargetDir, nSize);
    if (nResult < 0) then

		svTemp = "Kan inte uppdatera " + APP_NAME + " med kart-pack nr. 1 version" + CONTENT_VERSION + 
		         ".\n\nKontrollera att " + APP_NAME + " är korrekt installerat!";

	    MessageBox(svTemp, WARNING);
        exit;
    endif;

    // Check version number of what's already installed
    nType = REGDB_STRING;
    nSize = -1;
    nResult = RegDBGetKeyValueEx(svRegKey, "Version", nType, svVersion, nSize);

	if (nResult != 0) then
		svVersion = "1.0";
	endif;

    if (nResult != 0 || StrCompare(svVersion, UPDATE_VERSION) < 0) then

		svTemp = "Kan inte uppdatera " + APP_NAME + " version " + svVersion + " med kart-pack nr. 1 version" +
		         CONTENT_VERSION + ".\n\nFörst måste du uppdatera " + APP_NAME + " till version " +
				 UPDATE_VERSION + ".\n\nDu kan ladda ner de senaste uppdateringarna till " +
				 APP_NAME + " på: http://www.the-operative.com";

	    MessageBox(svTemp, INFORMATION);
        exit;
    endif;

    // Show status window
    Disable(FEEDBACK_FULL);
    Enable(STATUS);
	Enable(INDVFILESTATUS);
    PlaceWindow(STATUS, CENTERED, 0, LOWER_RIGHT);
    SetStatusWindow(0, "Uppdaterar " + APP_NAME + "...");

    // Copy game files
    StatusUpdate(ON, 100);
    SRCDIR    = svSrcDir ^ "GAME";
    TARGETDIR = svTargetDir;
    CopyFile("*.*", "*.*");

    // Copy language-specific files...
    SRCDIR = svSrcDir ^ "GAME\\SWEDISH";
    CopyFile("*.*", "*.*");

    // Display done message
    SetStatusWindow(1000, "Uppdatering av kart-pack nr. 1 klar!");

    // Set new registry keys
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    RegDBSetKeyValueEx(svRegKey, "Content Version", REGDB_STRING, CONTENT_VERSION, -1);
    RegDBSetKeyValueEx(svRegKey, "Content Command Line", REGDB_STRING, CONTENT_COMMAND, -1);

    // Do the readme...

	svTemp = "Uppdateringen av kart-pack nr. 1 till " + APP_NAME + " är klar! Vill du läsa README-filen nu?";

    if (AskYesNo(svTemp, YES) = YES) then
		LaunchAppAndWait("NOTEPAD.EXE " + svTargetDir ^ "READMEC001.TXT", "", NOWAIT);
    endif;

exit;
