Exemplo n.º 1
0
int recursiveMkdir(char *pathname, int mode){
	char *p;
	int r;
	//if (pathname[strlen(pathname) - 1] == '/')
	//	pathname[strlen(pathname) - 1] = '\0';
	r = mkdir(pathname, mode);
	if (r != 0) {
		/* On failure, try creating parent directory. */
		p = strrchr(pathname, '/');
		if (p != NULL) {
			*p = '\0';
			recursiveMkdir(pathname, 0755);
			*p = '/';
			r = mkdir(pathname, mode);
		}
	}
	return r;
}
Exemplo n.º 2
0
// jitProfileInitialize
//
static int jitProfileInitialize(AMDTJitProfileEnv* pEnv)
{
    int             ret = 0;
    std::wstring    profileDataDir;

    if (true == gAMDTJitProfileInitialized)
    {
        return AMDT_JITPROFILE_SUCCESS;
    }

    gJitPID = (NULL == pEnv) ? _getpid() : pEnv->processId;

    // Get the command-line to obtain the Application name;
    // gJitCmd will contain the name of JIT Application;
    ret = getCmdline(pEnv);

    if (AMDT_JITPROFILE_SUCCESS != ret)
    {
        jitError(pEnv, "Could not get the command line");
        return ret;
    }

    if (gJitVerbose)
    {
        wprintf(L"Command Line: %s\n", gJitCmd.c_str());
    }

    // Get the dir path in which the JIT profile data files will be written
    // Note: getProfileDataDir gives gSampleDir and profileDataDir
    ret = getProfileDataDir(profileDataDir);

    if (AMDT_JITPROFILE_SUCCESS != ret)
    {
        jitError(pEnv, "Could not get profile data dir for JIT application");
        return ret;
    }

    if (gJitVerbose)
    {
        wprintf(L"The JIT Profile data dir is " STR_FORMAT L".\n",
                profileDataDir.c_str());
    }

    // Save the profileDataDir for future use..
    gProfileDataDir = profileDataDir;

#if AMDT_BUILD_TARGET == AMDT_WINDOWS_OS
    // The directory access right is 771
    int j = recursiveMkdir(profileDataDir.c_str());

    if (0 != j)
    {
        wprintf(L"The sample directory " STR_FORMAT L" was not able to be created\n",
                profileDataDir.c_str());
        return AMDT_JITPROFILE_FAILED;
    }

    profileDataDir = gProfileDataDir;
#else
    // Linux
    struct stat buf;
    string tmpStr(profileDataDir.begin(), profileDataDir.end());

    if (stat(tmpStr.c_str(), &buf) != 0)
    {
        if (mkdir(tmpStr.c_str(), 0x01fd) != 0)
        {
            jitError(pEnv, "Cannot create directory %s",
                     profileDataDir.c_str());
            return AMDT_JITPROFILE_FAILED;
        }
    }

#endif

    // Save the profileDataDir for future use..
    gProfileDataDir = profileDataDir;

    // Construct the JCL filename
    wchar_t jclFile[OS_MAX_PATH] = { L'\0' };

    swprintf(jclFile, OS_MAX_PATH - 1, STR_FORMAT PATH_SEPARATOR L"%d.jcl", profileDataDir.c_str(), gJitPID);

    // Initialize JCLWriter
    gJCLWriter = new JclWriter(jclFile, gJitCmd.c_str(), gJitPID);

    if (NULL == gJCLWriter)
    {
        jitError(pEnv, "Error: Out of Memory");
        return AMDT_JITPROFILE_FAILED;
    }

    // This just writes the header record
    gJCLWriter->Initialize();

    return AMDT_JITPROFILE_SUCCESS;
} // jitProfileInitialize
int downloadCb(){
	IupSetFunction("IDLE_ACTION", NULL);
	IupLoopStep();
	char *cachePath = path_get_nwjs_cache();
	char *indexJsonPath = string_concat(2, cachePath, "../index.json");
	recursiveMkdir(cachePath, 0755); //Create directories if they don't already exist
	indexJsonFile_t versionIndex = {};
	if(download(INDEXJSON_URL, indexJsonPath, genericCb) != DOWNLOAD_SUCCESS){
		printf("[nwjsmanager][DEBUG] Failed to download version index at URL '%s'. Cached version will be used if available.\n", INDEXJSON_URL);
	}
	indexJson_file_parse(indexJsonPath, &versionIndex);
	if(versionIndex.nwjsVersionCount != 0){
		if(update_required(&versionIndex)){
			Ihandle *info = IupGetHandle("info");
			IupSetStrf(info, "TITLE", "Downloading nwjsmanager update (you are running v%s, but v%d.%d.%d is available).", NWJSMANAGER_VERSION, versionIndex.nwjsmanagerLatestVersion.major, versionIndex.nwjsmanagerLatestVersion.minor, versionIndex.nwjsmanagerLatestVersion.patch);
			if(!update_install(&versionIndex, progressCb, _argc, _argv)){
				IupMessage(app->name, "Failed to install update!");
				return IUP_CLOSE;
			}
		}
		nwjsVersion_t *launchVersion = NULL;
		for(int i = 0; i < versionIndex.nwjsVersionCount; i++)
			if(packageJson_file_is_nw_version_OK(app, versionIndex.nwjsVersions[i].version) && (!launchVersion || semver_gt(versionIndex.nwjsVersions[i].version, launchVersion->version)))
				launchVersion = &versionIndex.nwjsVersions[i];
		if(!launchVersion){
			IupMessage(app->name, "Error: no nw.js version compatible with the application was found. Please try to reinstall the application, or contact the developer if the problem persists.");
		}else{
			printf("[nwjsmanager][DEBUG] Downloading nw.js %d.%d.%d\n", launchVersion->version.major, launchVersion->version.minor, launchVersion->version.patch);
			char *versionName = malloc(255); //Using 255 as max length (see https://github.com/mojombo/semver/blob/master/semver.md#does-semver-have-a-size-limit-on-the-version-string)
			sprintf(versionName, "v%d.%d.%d", launchVersion->version.major, launchVersion->version.minor, launchVersion->version.patch);
			nwjsDownload_t *downloads = &launchVersion->defaultDownloads;
			char *url;
			#ifdef _WIN32
				//Actually on Windows only a 32-bit binary is distributed since it will work out-of-the box thanks to Wow64. The IsWow64 function (see win-only/IsWow64.c) is used to detect at runtime if we are on a 64-bit system and properly select the nw.js architecture.
				if(IsWow64())
					url = downloads->win64;
				else
					url = downloads->win32;
			#else
				//On linux, architecture is detected at compile time because two different binaries are distributed (i386 and x86_64)
				#ifdef __x86_64__
					url = downloads->linux64;
				#else
					url = downloads->linux32;
				#endif
			#endif
			char *file = string_concat(2, cachePath, "download");
			int result = download(url, file, progressCb);
			if(result == DOWNLOAD_SUCCESS){
				result = extractArchive(file, cachePath);
				remove(file);
				char *oldName = strrchr(url, '/') + sizeof(char);
				char *oldNameEnd = strstr(oldName, ".zip");
				if(!oldNameEnd)
					oldNameEnd = strstr(oldName, ".tar.gz");
				*oldNameEnd = '\0';
				char *oldPath = string_concat(2, cachePath, oldName);
				*oldNameEnd = '.';
				char *newPath = string_concat(2, cachePath, versionName);
				rename(oldPath, newPath);
				free(oldPath);
				#ifndef _WIN32
					recursiveChmod(newPath, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH);
				#endif
				free(newPath);
				globalResult = DOWNLOADERGUI_SUCCESS;
			}
			free(file);
			free(versionName);
		}
	}else
		IupMessage(app->name, "Error: this application requires the nw.js runtime, but a suitable version of the runtime files isn't installed. An attempt was done to download it, but it wasn't possible to retrive the version index.\nPlease check your Internet connection (this is necessary only for the first run of the application). Also, be sure the current user is allowed to write to the nw.js binary cache directory.");
	indexJson_file_free(&versionIndex);
	free(indexJsonPath);
	free(cachePath);
	return IUP_CLOSE;
}
Exemplo n.º 4
0
int DrawTool::processOptions (int argc, char ** argv)
{
	try {
        int c;
        int index;
        static struct option long_options [] = {       
            {"help", no_argument, NULL, 'h'},
            {"outfile", required_argument, NULL, 'o'},
            {"colour",required_argument,NULL,'c'},
            {"bins", required_argument, NULL, 'b'},
            {"format", required_argument, NULL, 'f'},
            {"algorithm", required_argument, NULL, 'a'},
            {"groups", required_argument, NULL, 'g'},
            {0,0,0,0}
        };
        
        bool algo = false, outformat = false;
        while((c = getopt_long(argc, argv, "hg:c:a:f:o:b:", long_options, &index)) != -1)
        {
            switch(c)
            {
                case 'h':
                {
                    drawUsage ();
                    exit(1);
                    break;
                }
                case 'g':
                {
                    generateGroupsFromString (optarg);
                    break;
                }
                    
                case 'o':
                {
                    DT_OutputFile = optarg;
                    if (DT_OutputFile[DT_OutputFile.length() - 1] != '/')
                    {
                        DT_OutputFile += '/';
                    }
                    
                    // check if our output folder exists
                    struct stat file_stats;
                    if (0 != stat(DT_OutputFile.c_str(),&file_stats)) 
                    {
                        recursiveMkdir(DT_OutputFile);
                    }
                    break;
                }
                case 'c':
                {
                    if (!strcmp(optarg, "red-blue") ) {
                        DT_ColourType = RED_BLUE;
                    } else if (!strcmp(optarg, "red-blue-green")) {
                        DT_ColourType = RED_BLUE_GREEN;
                    } else if (!strcmp(optarg, "blue-red")) {
                        DT_ColourType = BLUE_RED;
                    } else if (!strcmp(optarg, "green-blue-red")) {
                        DT_ColourType = GREEN_BLUE_RED;
                    } else {
                        throw crispr::input_exception("Not a known color type");
                    }
                    break;
                } 
                case 'f':
                {
                    DT_OutputFormat = optarg;
                    outformat = true;
                    break;
                }
                case 'a':
                {
                    if (!strcmp(optarg, "dot") || 
                        !strcmp(optarg, "neato") || 
                        !strcmp(optarg, "fdp") || 
                        !strcmp(optarg, "sfdp") ||
                        !strcmp(optarg, "twopi") || 
                        !strcmp(optarg, "circo")) {
                        DT_RenderingAlgorithm = optarg;       
                    } else {
                        throw crispr::input_exception("Not a known Graphviz rendering algorithm");
                    }
                    algo = true;
                    break;
                }
                case 'b':
                {
                    int i;
                    if (from_string<int>(i, optarg, std::dec)) {
                        if (i > 0) {
                            DT_Bins = i;
                        } else {
                            throw crispr::input_exception("The number of bins of colour must be greater than 0");
                        }
                    } else {
                        throw crispr::runtime_exception(__FILE__, __LINE__, __PRETTY_FUNCTION__,"could not convert string to int");
                    }
                    break;
                }
                default:
                {
                    drawUsage();
                    exit(1);
                    break;
                }
            }
        }
        if (!(algo & outformat) ) {
            throw crispr::input_exception("You must specify both -a and -f on the command line");
        }

    } catch (crispr::input_exception& e) {
        std::cerr<<e.what()<<std::endl;
        drawUsage();
        exit(1);
    } catch (crispr::runtime_exception& e) {
        std::cerr<<e.what()<<std::endl;
        exit(1);
    }
    return optind;
}