Example #1
0
    int Bootstrap()
    {
        applicationHome = GetApplicationHomePath();
        string manifestPath = FileUtils::Join(applicationHome.c_str(), MANIFEST_FILENAME, NULL);
        if (!FileUtils::IsFile(manifestPath))
        {
            string error("Application packaging error: no manifest was found at: ");
            error.append(manifestPath);
            ShowError(error);
            return __LINE__;
        }

        app = Application::NewApplication(applicationHome);
        if (app.isNull())
        {
            string error("Application packaging error: could not read manifest at: ");
            error.append(manifestPath);
            ShowError(error);
            return __LINE__;
        }
        app->SetArguments(argc, argv);

        // Look for a .update file in the app data directory
        FindUpdate();
    
        vector<SharedDependency> missing = app->ResolveDependencies();
        if (app->HasArgument("debug"))
        {
            vector<SharedComponent> resolved = app->GetResolvedComponents();
            for (size_t i = 0; i < resolved.size(); i++)
            {
                SharedComponent c = resolved[i];
                std::cout << "Resolved: (" << c->name << " " 
                    << c->version << ") " << c->path << std::endl;
            }
            for (size_t i = 0; i < missing.size(); i++)
            {
                SharedDependency d = missing.at(i);
                std::cerr << "Unresolved: " << d->name << " " 
                    << d->version << std::endl;
            }
        }

        bool forceInstall = app->HasArgument("--force-install");
        if (forceInstall || !missing.empty() || !app->IsInstalled() ||
            !updateFile.empty())
        {
            // If this list of dependencies incluces the SDKs, just install
            // those -- we assume that they also supply our other dependencies.
            missing = FilterForSDKInstall(missing);

            if (!RunInstaller(missing, forceInstall))
            {
                return __LINE__;
            }

            missing = app->ResolveDependencies();
        }

        if (missing.size() > 0 || !app->IsInstalled())
        {
            // The user cancelled or the installer encountered an error
            // -- which is should have already reported. We're not checking
            // for updateFile.empty() here, because if the user cancelled
            // the update, we just want to start the application as usual.
            return __LINE__;
        }
    
        // Construct a list of module pathnames for setting up library paths
        std::ostringstream moduleList;
        vector<SharedComponent>::iterator i = app->modules.begin();
        while (i != app->modules.end())
        {
            SharedComponent module = *i++;
            moduleList << module->path << MODULE_SEPARATOR;
        }

        EnvironmentUtils::Set(BOOTSTRAP_ENV, "YES");
        EnvironmentUtils::Set("KR_HOME", app->path);
        EnvironmentUtils::Set("KR_RUNTIME", app->runtime->path);
        EnvironmentUtils::Set("KR_MODULES", moduleList.str());

        BootstrapPlatformSpecific(moduleList.str());
        if (!updateFile.empty())
        {
            FileUtils::DeleteFile(updateFile);
        }

        string error = Blastoff();
        // If everything goes correctly, we should never get here
        error = string("Launching application failed: ") + error;
        ShowError(error, false);
        return __LINE__;
    }
Example #2
0
void RunScript(FILE * script, const char * path)
{
	ErrFunc_f old = InstallErrFunc(ScriptError, NULL);
	char * mem;
	int len, ok;
	char	strbuf[1024];
	strcpy(strbuf, path);
	strcat(strbuf, DIR_STR);
	MakeDirExist(strbuf);
	strcat(strbuf, "Installer Log.txt");
	scriptLog = fopen(strbuf, "w");
	if (scriptLog) fprintf(scriptLog, "Installing X-Plane to %s.\n", path);
	char	from_buf[1024], to_buf[1024], partial[1024];
	const char *	app_path = GetApplicationPath();
	if (app_path == NULL)
	{
		return;
	}
	bool	condition = true;
	while (get_line(script, strbuf, sizeof(strbuf)-1))
	{
		char * t;
		char * p = strbuf;
		t = next_token(&p);
		if (t == NULL) continue;
		if (!strcmp(t, "NOCONDITION"))
		{
			condition = true;
		}
		if (!strcmp(t, "ELSE"))
		{
			condition = !condition;
		}
		if (!strcmp(t, "MESSAGE"))
		{
			if (scriptLog) fprintf(scriptLog, "Note: %s\n", p);
			DoUserAlert(p);
		}
		if (!strcmp(t, "CONDITION"))
		{
			if (scriptLog) fprintf(scriptLog, "Checking: %s\n", p);
			condition = ConfirmMessage(p, "Yes", "No");
			if (scriptLog) fprintf(scriptLog, "Answer: %s\n", condition ? "yes" : "no");
		}
		if (!strcmp(t, "UPDATE"))
		{
			if (scriptLog) fprintf(scriptLog, "Running update.\n");
			if (condition)
				RunInstaller(path);
		}
		if (!strcmp(t, "COPY"))
		{
			t = next_token(&p);
			float indi = -1.0;
			sprintf(msgBuf, "Installing %s...", t);
			ShowProgressMessage(msgBuf, &indi);
			strcpy(from_buf, app_path);
			strip_to_delim(from_buf,DIR_CHAR);
			strcat(from_buf, t);
			strcpy(to_buf, path);
			strcat(to_buf, DIR_STR);
			strcat(to_buf, p);
			normalize_dir_chars(to_buf);
			normalize_dir_chars(from_buf);
			if (condition)
			{
				if (scriptLog) fprintf(scriptLog, "Copying %s to %s\n", from_buf, to_buf);
				ok = FileToBlock(from_buf, &mem, &len);
				if (!ok) return;
				ok = BlockToFile(to_buf, mem);
				if (!ok) return;
				free(mem);
			} else {
				if (scriptLog) fprintf(scriptLog, "Not copying %s to %s\n", from_buf, to_buf);
			}
		}
		if (!strcmp(t, "UNZIP"))
		{
			t = next_token(&p);
			sprintf(msgBuf, "Installing %s...", t);
			strcpy(from_buf, app_path);
			strip_to_delim(from_buf,DIR_CHAR);
			strcat(from_buf, t);
			if (!strcmp(p, "/"))
			{
				strcpy(partial, path);
				strcat(partial, DIR_STR);
			} else {
				strcpy(partial, path);
				strcat(partial, DIR_STR);
				strcat(partial, p);
			}
			normalize_dir_chars(partial);
			normalize_dir_chars(from_buf);

			if (condition)
			{
				if (scriptLog) fprintf(scriptLog, "Unzipping %s to %s\n", from_buf, partial);
				unzFile unz = unzOpen(from_buf);
				if (unz == NULL)
				{
					ReportError("Unable to open zip file.", EUNKNOWN, from_buf);
					return;
				}
				unz_global_info		global;
				unzGetGlobalInfo(unz, &global);
				unzGoToFirstFile(unz);
				int counter = 0;
				do {

					char				zip_path[1024];
					unz_file_info		info;
					unzGetCurrentFileInfo(unz, &info, zip_path, sizeof(zip_path),
						NULL, 0, NULL, 0);

					sprintf(msgBuf, "Installing %s...", zip_path);
					float prog = (global.number_entry > 0) ? ((float) counter / (float) global.number_entry) : -1.0;
					ShowProgressMessage(msgBuf, &prog);

					++counter;

					strcpy(to_buf, partial);
					strcat(to_buf, zip_path);
					normalize_dir_chars(to_buf);
					strip_to_delim(to_buf, DIR_CHAR);
					MakeDirExist(to_buf);

					if (info.uncompressed_size == 0)
						continue;

					char * mem = (char *) malloc(info.uncompressed_size);
					if (!mem) { ReportError("Out of memory", ENOMEM, NULL); return; }
					unzOpenCurrentFile(unz);
					int result = unzReadCurrentFile(unz,mem, info.uncompressed_size);
					if (result != info.uncompressed_size)
					{	ReportError("Could not read installer archive.", EUNKNOWN, zip_path); }
					unzCloseCurrentFile(unz);

					strcpy(to_buf, partial);
					strcat(to_buf, zip_path);
					normalize_dir_chars(to_buf);

					FILE * fi = fopen(to_buf, "wb");
					if (fi == NULL)
					{
						ReportError("Could not create file", errno, to_buf);
						return;
					}
					result = fwrite(mem, 1, info.uncompressed_size, fi);
					if (result != info.uncompressed_size)
					{ ReportError("Could not read installer archive.", errno, to_buf); }
					fclose(fi);
					free(mem);
				} while(unzGoToNextFile(unz) == UNZ_OK);
				unzClose(unz);
			} else {
				if (scriptLog) fprintf(scriptLog, "Not unzipping %s to %s\n", from_buf, partial);
			}
		}
	}
	InstallErrFunc(old, NULL);
	if (scriptLog) fprintf(scriptLog, "Installer completed successfully.\n");
	if (scriptLog) fclose(scriptLog);
	DoUserAlert("Installation was successful!");
}
Example #3
0
int APIENTRY
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  WNDCLASS  wc;
  HWND      hwndFW;

	hInst = hInstance;
	LoadString(hInst, IDS_TITLE, szTitle, MAX_BUF);

  // Parse the command line
  ParseCommandLine(lpCmdLine);
  
  /*  Allow multiple installer instances with the 
      provision that each instance is guaranteed 
      to have its own unique setup directory 
   */
  if(FindWindow("NSExtracting", "Extracting...") != NULL ||
    (hwndFW = FindWindow(CLASS_NAME_SETUP_DLG, NULL)) != NULL ||
    (hwndFW = FindWindow(CLASS_NAME_SETUP, NULL)) != NULL)
  {
    if (gbAllowMultipleInstalls)
    {
      char szTempPath[MAX_BUF];
      GetFullTempPathName("", MAX_BUF, szTempPath);
      DWORD dwLen = lstrlen(gszWizTempDir);

      for(int i = 1; i <= 100 && (FileExists(szTempPath) != FALSE); i++)
      {
        itoa(i, (gszWizTempDir + dwLen), 10);
        GetFullTempPathName("", MAX_BUF, szTempPath);
      }

      if (FileExists(szTempPath) != FALSE)
      {
        MessageBox(NULL, "Cannot create temp directory", NULL, MB_OK | MB_ICONEXCLAMATION);
        exit(1);
      }
    }
    else
    {
      if (hwndFW!=NULL)
      {
        ShowWindow(hwndFW, SW_RESTORE);
        SetForegroundWindow(hwndFW);
      }
      return(1);
    }
  }

	// Figure out the total size of the resources
	EnumResourceNames(NULL, "FILE", (ENUMRESNAMEPROC)SizeOfResourcesProc, 0);

  // Register a class for the gauge
  memset(&wc, 0, sizeof(wc));
  wc.lpfnWndProc   = (WNDPROC)GaugeWndProc;
  wc.hInstance     = hInstance;
  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  wc.lpszClassName = "NSGauge";
  RegisterClass(&wc);

  // Register a class for the main dialog
  memset(&wc, 0, sizeof(wc));
  wc.style         = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
  wc.lpfnWndProc   = DefDlgProc;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = DLGWINDOWEXTRA;
  wc.hInstance     = hInstance;
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  wc.lpszClassName = "NSExtracting";
  RegisterClass(&wc);

  if(dwMode != SILENT)
  {
	  // Display the dialog box
	  dlgInfo.hWndDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_EXTRACTING), NULL, (DLGPROC)DialogProc);
	  UpdateWindow(dlgInfo.hWndDlg);
  }

	// Extract the files
	EnumResourceNames(NULL, "FILE", (ENUMRESNAMEPROC)ExtractFilesProc, 0);
	
	// Launch the install program and wait for it to finish
	RunInstaller();
	return 0;  
}