示例#1
0
static void
ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsILocalFile *statusFile,
            nsIFile *appDir, int appArgc, char **appArgv)
{
    nsresult rv;

    // Steps:
    //  - mark update as 'applying'
    //  - copy updater into update dir
    //  - run updater w/ appDir as the current working dir

    nsCOMPtr<nsIFile> updater;
    if (!CopyUpdaterIntoUpdateDir(greDir, appDir, updateDir, updater)) {
        LOG(("failed copying updater\n"));
        return;
    }

    // We need to use the value returned from XRE_GetBinaryPath when attempting
    // to restart the running application.
    nsCOMPtr<nsILocalFile> appFile;

#if defined(XP_MACOSX)
    // On OS X we need to pass the location of the xulrunner-stub executable
    // rather than xulrunner-bin. See bug 349737.
    GetXULRunnerStubPath(appArgv[0], getter_AddRefs(appFile));
#else
    XRE_GetBinaryPath(appArgv[0], getter_AddRefs(appFile));
#endif

    if (!appFile)
        return;

#ifdef XP_WIN
    nsAutoString appFilePathW;
    rv = appFile->GetPath(appFilePathW);
    if (NS_FAILED(rv))
        return;
    NS_ConvertUTF16toUTF8 appFilePath(appFilePathW);

    nsAutoString updaterPathW;
    rv = updater->GetPath(updaterPathW);
    if (NS_FAILED(rv))
        return;

    NS_ConvertUTF16toUTF8 updaterPath(updaterPathW);

#else
    nsCAutoString appFilePath;
    rv = appFile->GetNativePath(appFilePath);
    if (NS_FAILED(rv))
        return;

    nsCAutoString updaterPath;
    rv = updater->GetNativePath(updaterPath);
    if (NS_FAILED(rv))
        return;

#endif

    // Get the directory to which the update will be applied. On Mac OSX we need
    // to apply the update to the Foo.app directory which is the parent of the
    // parent of the appDir. On other platforms we will just apply to the appDir.
#if defined(XP_MACOSX)
    nsCAutoString applyToDir;
    {
        nsCOMPtr<nsIFile> parentDir1, parentDir2;
        rv = appDir->GetParent(getter_AddRefs(parentDir1));
        if (NS_FAILED(rv))
            return;
        rv = parentDir1->GetParent(getter_AddRefs(parentDir2));
        if (NS_FAILED(rv))
            return;
        rv = parentDir2->GetNativePath(applyToDir);
    }
#elif defined(XP_WIN)
    nsAutoString applyToDir;
    rv = appDir->GetPath(applyToDir);
#else
    nsCAutoString applyToDir;
    rv = appDir->GetNativePath(applyToDir);
#endif
    if (NS_FAILED(rv))
        return;

#if defined(XP_WIN)
    nsAutoString updateDirPathW;
    rv = updateDir->GetPath(updateDirPathW);

    NS_ConvertUTF16toUTF8 updateDirPath(updateDirPathW);
#else
    nsCAutoString updateDirPath;
    rv = updateDir->GetNativePath(updateDirPath);
#endif

    if (NS_FAILED(rv))
        return;

    // Get the current working directory.
    char workingDirPath[MAXPATHLEN];
    rv = GetCurrentWorkingDir(workingDirPath, sizeof(workingDirPath));
    if (NS_FAILED(rv))
        return;

    if (!SetStatus(statusFile, "applying")) {
        LOG(("failed setting status to 'applying'\n"));
        return;
    }

    // Construct the PID argument for this process.  If we are using execv, then
    // we pass "0" which is then ignored by the updater.
#if defined(USE_EXECV)
    NS_NAMED_LITERAL_CSTRING(pid, "0");
#else
    nsCAutoString pid;
    pid.AppendInt((PRInt32) getpid());
#endif

    int argc = appArgc + 4;
    char **argv = new char*[argc + 1];
    if (!argv)
        return;
    argv[0] = (char*) updaterPath.get();
    argv[1] = (char*) updateDirPath.get();
    argv[2] = (char*) pid.get();
    if (appArgc) {
        argv[3] = workingDirPath;
        argv[4] = (char*) appFilePath.get();
        for (int i = 1; i < appArgc; ++i)
            argv[4 + i] = appArgv[i];
        argv[4 + appArgc] = nsnull;
    } else {
        argv[3] = nsnull;
        argc = 3;
    }

    LOG(("spawning updater process [%s]\n", updaterPath.get()));

#if defined(USE_EXECV)
    chdir(applyToDir.get());
    execv(updaterPath.get(), argv);
#elif defined(XP_WIN)
    _wchdir(applyToDir.get());

    if (!WinLaunchChild(updaterPathW.get(), appArgc + 4, argv))
        return;
    _exit(0);
#else
    PRStatus status;
    PRProcessAttr *attr;

    attr = PR_NewProcessAttr();
    if (!attr)
        goto end;

    status = PR_ProcessAttrSetCurrentDirectory(attr, applyToDir.get());
    if (status != PR_SUCCESS)
        goto end;

#ifdef XP_MACOSX
    CommandLineServiceMac::SetupMacCommandLine(argc, argv, PR_TRUE);
#endif

    PR_CreateProcessDetached(updaterPath.get(), argv, nsnull, attr);
    exit(0);

end:
    PR_DestroyProcessAttr(attr);
    delete[] argv;
#endif
}
示例#2
0
NPError 
NPP_SetWindow(NPP instance, NPWindow* window)
{
    PluginInstance* This;
    NPSetWindowCallbackStruct *ws_info;
    const SDL_VideoInfo* info = NULL;
    char windowEnv[3][500];
   	
    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;

    This = (PluginInstance*) instance->pdata;

    if (This == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;

    ws_info = (NPSetWindowCallbackStruct *)window->ws_info;

    fprintf(stderr,"Setting up events for viewer\n");
    int app_event_mask = !ButtonPressMask;
    XSelectInput(ws_info->display, (int)(window->window), app_event_mask);

    fprintf(stderr,"Loading environment for viewer:\n");
    sprintf(windowEnv[0],"SDL_WINDOWID=%d",(int)(window->window));
    sprintf(windowEnv[1],"FFW_WINX=%d",(int)(window->width));
    sprintf(windowEnv[2],"FFW_WINY=%d",(int)(window->height));
    int i=0;
    for(i=0; i<3; i++) putenv(windowEnv[i]);

    fprintf(stderr, "Window=(%i)\n", (int)(window->window));
    fprintf(stderr, "W=(%i) H=(%i)\n",(int)window->width, (int)window->height);

/*
    if(SDL_Init(SDL_INIT_EVERYTHING)==-1) return NPERR_GENERIC_ERROR;
    info = SDL_GetVideoInfo();
	if(!info) { fprintf(stderr,"err1\n"); return NPERR_GENERIC_ERROR; }

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
	

	if((SDL_SetVideoMode(window->x,window->y,0,SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_ASYNCBLIT ))==0) { fprintf(stderr,"err2\n"); return NPERR_GENERIC_ERROR; }
	glViewport(0,0,(GLsizei) window->x , (GLsizei) window->y );
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D (0.0, (GLdouble) window->x, 0.0, (GLdouble) window->y);
	/*glEnable(GL_LINE_SMOOTH);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glClearColor(1,0,0,1);*/
	/**/
#ifdef MOZ_X11
//    if (This->window == (Window) window->window) {
        /* The page with the plugin is being resized.
           Save any UI information because the next time
           around expect a SetWindow with a new window
           id.
        */
//        return NPERR_NO_ERROR;
 //   } else {

      This->window = (Window) window->window;
      This->x = window->x;
      This->y = window->y;
      This->width = window->width;
      This->height = window->height;
      This->display = ws_info->display;
      This->visual = ws_info->visual;
      This->depth = ws_info->depth;
      This->colormap = ws_info->colormap;
      makePixmap(This);
      makeWidget(This);
//    }
#endif  /* #ifdef MOZ_X11 */
    if (viewer_proc == NULL) {
        char viewerArgs[2][50];
        PRProcessAttr* viewerProcAttr = PR_NewProcessAttr();
        PR_ProcessAttrSetCurrentDirectory(viewerProcAttr,"/slbrowser/");
        sprintf(viewerArgs[0],"/slbrowser/packaged/secondlife\0");
        sprintf(viewerArgs[1],"--autologin\0");
        fprintf(stderr,"Starting viewer!\n");
        viewer_proc = PR_CreateProcess("/slbrowser/secondlife",NULL,NULL,viewerProcAttr);
        PR_DetachProcess(viewer_proc);
    }

    return NPERR_NO_ERROR;
}