Example #1
0
void chooseFileNative( char *title, char *path, int openingFile, char *okMsg, char *cancelMsg ) {
	char szFileName[MAX_PATH] = "";
	ZFileSpec fs( path );
	if( !openingFile ) {
		strcpy( szFileName, fs.getFile() );
	}

	// Windows changes the working folder when you choose a file to open or 
	// save.  This makes using relative paths in our apps a pain, so I'm going
	// to save the cwd and restore it to defeat this behavior.
	char cwd[1024];
	getcwd( cwd, 1024 );
	extern void trace( char *msg, ... );

	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = (HWND)glfwZBSExt_GetHWND();
	ofn.lpstrFilter = getWindowsFilterStringFromPath( path );
	ofn.lpstrFile = szFileName;
	ofn.lpstrTitle = title;

	// Windows will ignore out initDir request unless we use backslashes, and
	// ensure there is no trailing slash...
	extern char * convertSlashes( char *, char c=0 );
	extern char * stripTrailingSlashes( char * );
		// these are in ZFileSPec, and were static, but I changed that use use it here. (tfb)
	ofn.lpstrInitialDir = stripTrailingSlashes( convertSlashes( fs.getDir(), '\\' ) );
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
	if( openingFile ) {
		ofn.Flags = ofn.Flags | OFN_FILEMUSTEXIST;
	}
	ofn.lpstrDefExt = fs.getExt();

	int status = 0;
	if( openingFile ) {
		status = GetOpenFileName( &ofn );
	}
	else {
		status = GetSaveFileName( &ofn );
	}
	if( status ) {
		if( okMsg ) {
			zMsgQueue( "%s filespec='%s'", okMsg, escapeQuotes( convertSlashes( szFileName, '/' ) ) );
		}
	}
	else if( cancelMsg ) {
		zMsgQueue( cancelMsg );
	}

	zFileSpecChdir( cwd );
	getcwd( cwd, 1024 );
}
Example #2
0
int W_RecordGetIdx(char *filename)
{
	int     i;
	char    buffer[RECORD_FILENAMELEN];

	// We have to make sure the slashes are correct.
	strcpy(buffer, filename);
	convertSlashes(buffer);

	for(i = 0; i < numrecords; i++)
		if(!stricmp(records[i].filename, buffer))
			return i;
	return -1;
}
Example #3
0
/*
 * Sets a property value.
 *
 * @param property - the property name
 * @param value - the property value (zero terminated string)
 */
static void setProperty(WCHAR* context, WCHAR* property, WCHAR* value) {

    HKEY key;
    DWORD res;

    WCHAR *fullContext = convertSlashes(context);

    RegCreateKeyEx(
        HKEY_LOCAL_MACHINE,
        fullContext,
        0,
        NULL,
        REG_OPTION_NON_VOLATILE,
        KEY_ALL_ACCESS,
        NULL,
        &key,
        &res
    );

    if (key == 0) {
        goto finally;
    }

    RegSetValueEx(
        key,
        property,
        NULL,
        REG_SZ,  // we currently support only strings
        (UCHAR*)value,
        (wcslen(value)+1)*sizeof(WCHAR*)
    );

finally:

    if (key != 0) {
        RegCloseKey(key);
    }
    delete [] fullContext;
}
Example #4
0
boolean W_AddFile(const char *filename, boolean allowDuplicate)
{
	char    alterFileName[256];
	wadinfo_t header;
	DFILE  *handle;
	unsigned int length;
	filelump_t *fileinfo, singleinfo;
	filelump_t *freeFileInfo;
	filerecord_t *rec;
	const char *extension;

	// Filename given?
	if(!filename || !filename[0])
		return true;

	if((handle = F_Open(filename, "rb")) == NULL)
	{
		// Didn't find file. Try reading from the data path.
		R_PrependDataPath(filename, alterFileName);
		if((handle = F_Open(alterFileName, "rb")) == NULL)
		{
			Con_Message("W_AddFile: ERROR: %s not found!\n", filename);
			return false;
		}
		// We'll use this instead.
		filename = alterFileName;
	}

	// Do not read files twice.
	if(!allowDuplicate && !M_CheckFileID(filename))
	{
		F_Close(handle);		// The file is not used.
		return false;
	}

	Con_Message("W_AddFile: %s\n", M_Pretty(filename));

	// Determine the file name extension.
	extension = strrchr(filename, '.');
	if(!extension)
		extension = "";
	else
		extension++;			// Move to point after the dot.

	// Is it a zip/pk3 package?
	if(!stricmp(extension, "zip") || !stricmp(extension, "pk3"))
	{
		return Zip_Open(filename, handle);
	}

	// Get a new file record.
	rec = W_RecordNew();
	strcpy(rec->filename, filename);
	convertSlashes(rec->filename);
	rec->handle = handle;

	// If we're not loading for startup, flag the record to be a Runtime one.
	if(!loadingForStartup)
		rec->flags = FRF_RUNTIME;

	if(stricmp(extension, "wad") && stricmp(extension, "gwa"))
	{
		// Single lump file.
		fileinfo = &singleinfo;
		freeFileInfo = NULL;
		singleinfo.filepos = 0;
		singleinfo.size = F_Length(handle);
		M_ExtractFileBase(filename, singleinfo.name);
		rec->numlumps = 1;
	}
	else
	{
		// WAD file.
		F_Read(&header, sizeof(header), handle);
		if(!strncmp(header.identification, "JWAD", 4))
		{
			// This is treated like an IWAD, but we won't set the
			// iwadLoaded flag.
			rec->iwad = true;
		}
		else if(strncmp(header.identification, "IWAD", 4))
		{
			if(strncmp(header.identification, "PWAD", 4))
			{					// Bad file id
				Con_Error("Wad file %s doesn't have IWAD or PWAD id\n",
						  filename);
			}
		}
		else
		{
			// Found an IWAD.
			iwadLoaded = true;
			if(!stricmp(extension, "wad"))
				rec->iwad = true;
		}
		header.numlumps = LONG(header.numlumps);
		header.infotableofs = LONG(header.infotableofs);
		length = header.numlumps * sizeof(filelump_t);
		if(!(fileinfo = malloc(length)))
		{
			Con_Error("W_AddFile: fileinfo malloc failed\n");
		}
		freeFileInfo = fileinfo;
		F_Seek(handle, header.infotableofs, SEEK_SET);
		F_Read(fileinfo, length, handle);
		rec->numlumps = header.numlumps;
	}

	// Insert the lumps to lumpinfo, into their rightful places.
	W_InsertLumps(fileinfo, rec);

	if(freeFileInfo)
		free(freeFileInfo);

	PrimaryLumpInfo = lumpinfo;
	PrimaryLumpCache = lumpcache;
	PrimaryNumLumps = numlumps;

	// Print the 'CRC' number of the IWAD, so it can be identified.
	if(rec->iwad)
		Con_Message("  IWAD identification: %08x\n",
					W_CRCNumberForRecord(rec - records));

	// glBSP: Also load a possible GWA.
	if(!stricmp(extension, "wad"))
	{
		char    buff[256];

		strcpy(buff, filename);
		strcpy(buff + strlen(buff) - 3, "gwa");

		// If GL data exists, load it.
		if(F_Access(buff))
		{
			W_AddFile(buff, allowDuplicate);
		}
	}

	return true;
}
Example #5
0
File: pty.cpp Project: MarcMil/cdt
/*
 * Class:     org_eclipse_cdt_utils_pty_PTY
 * Method:    exec2
 * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[ILjava/lang/String;IZ)I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTY_exec2
	(JNIEnv *env, jobject jobj, jobjectArray jcmd, jobjectArray jenv, jstring jdir, jintArray jchannels, jstring jslaveName, jint masterFD, jboolean console)
{
    int fd;
    std::map<int, winpty_t*> :: iterator fd2pty_Iter;

    jint *channels = env->GetIntArrayElements(jchannels, 0);
    const wchar_t *cwdW = (const wchar_t *) env->GetStringChars(jdir, NULL);
    const char *pts_name = env->GetStringUTFChars(jslaveName, NULL);

	int pid = -1;

	int i;
    jint argc = env->GetArrayLength(jcmd);
    jint envc = env->GetArrayLength(jenv);

    if (channels == NULL)
        goto bail_out;

    fd = masterFD;
    fd2pty_Iter = fd2pty.find(fd);
    if (fd2pty_Iter != fd2pty.end()) {
        winpty_t* winpty = fd2pty_Iter -> second;
    	if (winpty != NULL) {
	    	std::vector<std::wstring> argVector;

		    for (i = 0; i < argc; i++) {
			    jstring j_str = (jstring) env->GetObjectArrayElement(jcmd, i);
			    const wchar_t *w_str = (const wchar_t *) env->GetStringChars(j_str, NULL);
			    if (i == 0) argVector.push_back(convertSlashes(w_str));
			    else argVector.push_back(w_str);
	            env->ReleaseStringChars(j_str, (const jchar *) w_str);
		        env->DeleteLocalRef(j_str);
		    }

            std::wstring envp;

		    for (i = 0; i < envc; i++) {
			    jstring j_str = (jstring) env->GetObjectArrayElement(jenv, i);
			    const wchar_t *w_str = (const wchar_t *) env->GetStringChars(j_str, NULL);
                envp.append(w_str);
                envp.push_back(L'\0');
	            env->ReleaseStringChars(j_str, (const jchar *) w_str);
		        env->DeleteLocalRef(j_str);
		    }

            std::wstring cmdLine = argvToCommandLine(argVector);
            const wchar_t *cmdLineW = cmdLine.c_str();

		    int ret = winpty_start_process(winpty,
                                           NULL,
                                           cmdLineW,
                                           cwdW,
                                           envp.c_str());

            if (ret == 0) {
			    // Success. Get the process id.
			    pid = winpty_get_process_id(winpty);
            }
	    }
    }

bail_out:
    env->ReleaseIntArrayElements(jchannels, channels, 0);
    env->ReleaseStringChars(jdir, (const jchar *) cwdW);
    env->ReleaseStringUTFChars(jslaveName, pts_name);

	return pid;
}