Ejemplo n.º 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 );
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: ASchurman/Far
/* Interprets the arguments passed from the command line and calls
 * the appropriate function in far.h.
 * Returns one of the return codes defined in far.h, or 4 for invalid command
 * line invocation of Far */
int main(int argc, char** argv)
{
    char* archiveName; // The name of the archive passed to Far
    char** filenames; // Pointer to the beginning of the filenames in argv,
                      // or NULL if there are no filenames.
    unsigned char numFiles; // The number of filenames passed to Far
    FAR_RTRN returnCode;
    
    if(argc < 3) // less than "Far" plus a KEY plus an ARCHIVE
    {
        invalidArgsError();
        return 1;
    }
    
    archiveName = argv[2];
    
    if(argc > 3) // if Far was passed at least one filename
    {
        numFiles = argc - 3;
        filenames = stripTrailingSlashes(&(argv[3]), numFiles);
    }
    else
    {
        filenames = NULL;
        numFiles = 0;
    }
    
    if(strcmp(argv[1], "r") == 0)
    {
        returnCode = farAdd(archiveName, filenames, numFiles);
    }
    else if(strcmp(argv[1], "x") == 0)
    {
        returnCode = farExtract(archiveName, filenames, numFiles);
    }
    else if(strcmp(argv[1], "d") == 0)
    {
        returnCode = farDelete(archiveName, filenames, numFiles);
    }
    else if(strcmp(argv[1], "t") == 0)
    {
        returnCode = farPrint(archiveName);
    }
    else // first arg is not a valid key
    {
        invalidArgsError();
        returnCode = 4;
    }
    
    if(filenames) freeCharArray(filenames, numFiles);
    return returnCode;
}
void FileInProjectFinder::setProjectDirectory(const QString &absoluteProjectPath)
{
    const QString newProjectPath = stripTrailingSlashes(absoluteProjectPath);

    if (newProjectPath == m_projectDir)
        return;

    const QFileInfo infoPath(newProjectPath);
    QTC_CHECK(newProjectPath.isEmpty()
              || (infoPath.exists() && infoPath.isAbsolute()));

    m_projectDir = newProjectPath;
    m_cache.clear();
}
Ejemplo n.º 4
0
char *ourDirName(char *origname)
{
    char *slash;
    char *name;

    name = strdup(origname);

    stripTrailingSlashes(name);

    slash = strrchr(name, '/');

    if (!slash) {
	/* No slash, must be current directory */
	free(name);
	/* strdup used, as the return value will be free()ed at some point */
	return strdup(".");
    } else {
	/* Remove any trailing slashes and final element. */
	while (slash > name && *slash == '/')
	    --slash;
	slash[1] = '\0';
	return name;
    }
}