Example #1
0
BBString *bbSystemRequestDir( BBString *text,BBString *dir ){

	BBString *str=&bbEmptyString;

	if( _usew ){
		LPMALLOC shm;
		ITEMIDLIST *idlist;
		BROWSEINFOW bi={0};
		wchar_t buf[MAX_PATH],*p;

		GetFullPathNameW( bbTmpWString(dir),MAX_PATH,buf,&p );
		
		bi.hwndOwner=GetActiveWindow();
		bi.lpszTitle=bbTmpWString( text );
		bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
		bi.lpfn=BrowseForFolderCallbackW;
		bi.lParam=(LPARAM)buf;
		
		beginPanel();
		idlist=SHBrowseForFolderW(&bi);
		endPanel();
		
		if( idlist ){
			SHGetPathFromIDListW( idlist,buf );
			str=bbStringFromWString( buf );
			//SHFree( idlist );	//?!?	
		}
	} else {
		LPMALLOC shm;
		ITEMIDLIST *idlist;
		BROWSEINFOA bi={0};
		char buf[MAX_PATH],*p;
		
		GetFullPathNameA( bbTmpCString(dir),MAX_PATH,buf,&p );

		bi.hwndOwner=GetActiveWindow();
		bi.lpszTitle=bbTmpCString( text );
		bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
		bi.lpfn=BrowseForFolderCallbackA;
		bi.lParam=(LPARAM)buf;
		
		beginPanel();
		idlist=SHBrowseForFolderA(&bi);
		endPanel();
		
		if( idlist ){
			SHGetPathFromIDListA( idlist,buf );
			str=bbStringFromCString( buf );
			//SHFree( idlist );	//?!?	
		}
	}
	return str;
}
Example #2
0
void remove_( BBString *path ){
	chmod_( path,0x1b6 );
	if( _bbusew ){
		_wremove( bbTmpWString(path) );
	}else{
		remove( bbTmpCString(path) );
	}
}
Example #3
0
int bbOpenURL( BBString *url ){
	int n;
	if( _usew ){
		n=(int)ShellExecuteW( 0,0,(wchar_t*)bbTmpWString(url),0,0,10 )>32;	//SW_SHOWDEFAULT
	}else{
		n=(int)ShellExecuteA( 0,0,bbTmpCString(url),0,0,10 )>32;	//SW_SHOWDEFAULT
	}
	return n;
}
Example #4
0
static int systemPanel( BBString *text,int flags ){
	int n;
	
	beginPanel();
	if( _usew ){
		n=MessageBoxW( GetActiveWindow(),bbTmpWString(text),appTitleW(),flags );
	}else{
		n=MessageBoxA( GetActiveWindow(),bbTmpCString(text),appTitleA(),flags );
	}
	endPanel();
	return n;
}
Example #5
0
int stat_( BBString *path,int *t_mode,int *t_size,int *t_mtime,int *t_ctime ){
	int i;
	struct _stat st;
	
	for( i=0;i<path->length;++i ){
		if( path->buf[i]=='<' || path->buf[i]=='>' ) return -1;
	}
	
	if( _bbusew ){
		if( _wstat( bbTmpWString(path),&st ) ) return -1;
	}else{
		if( _stat( bbTmpCString(path),&st ) ) return -1;
	}

	*t_mode=st.st_mode;
	*t_size=st.st_size;
	*t_mtime=st.st_mtime;
	*t_ctime=st.st_ctime;
	return 0;
}
Example #6
0
int system_( BBString *cmd ){
	int res;
	PROCESS_INFORMATION pi={0};
	
	if( _bbusew ){
		STARTUPINFOW si={sizeof(si)};
		wchar_t *tmp=bbTmpWString(cmd);
	
		if( CreateProcessW( 0,tmp,0,0,1,CREATE_DEFAULT_ERROR_MODE,0,0,&si,&pi ) ){
			WaitForSingleObject( pi.hProcess,INFINITE );
	
			res=GetExitCodeProcess( pi.hProcess,(DWORD*)&res ) ? res : -1;
	
			CloseHandle( pi.hProcess );
			CloseHandle( pi.hThread );
		}else{
			res=GetLastError();
		}
		
	} else {
		STARTUPINFO si={sizeof(si)};
		char *tmp=bbTmpCString(cmd);
	
		if( CreateProcessA( 0,tmp,0,0,1,CREATE_DEFAULT_ERROR_MODE,0,0,&si,&pi ) ){
			WaitForSingleObject( pi.hProcess,INFINITE );
	
			res=GetExitCodeProcess( pi.hProcess,(DWORD*)&res ) ? res : -1;
	
			CloseHandle( pi.hProcess );
			CloseHandle( pi.hThread );
		}else{
			res=GetLastError();
		}
	}
	return res;
}
Example #7
0
static const wchar_t *appTitleW(){
	return bbTmpWString( bbAppTitle );
}
Example #8
0
int rmdir_( BBString *path ){
	if( _bbusew ) return _wrmdir( bbTmpWString(path) );
	return _rmdir( bbTmpCString(path) );
}
Example #9
0
int mkdir_( BBString *path,int mode ){
	if( _bbusew ) return _wmkdir( bbTmpWString(path) );
	return _mkdir( bbTmpCString(path) );
}
Example #10
0
int chmod_( BBString *path,int mode ){
	if( _bbusew ) return _wchmod( bbTmpWString(path),mode );
	return _chmod( bbTmpCString(path),mode );
}
Example #11
0
int fputs_( BBString *str,int file ){
	if( _bbusew ) return fputws( bbTmpWString(str),(FILE*)file );
	return fputs( bbTmpCString(str),(FILE*)file );
}
Example #12
0
BBString *getenv_( BBString *str ){
	if( _bbusew ) return bbStringFromWString( _wgetenv( bbTmpWString(str) ) );
	return bbStringFromCString( getenv( bbTmpCString(str) ) );
}
Example #13
0
int putenv_( BBString *str ){
	if( _bbusew ) return _wputenv( bbTmpWString(str) );
	return putenv( bbTmpCString(str) );
}
Example #14
0
int puts_( BBString *str ){
	if( _bbusew ) return _putws( bbTmpWString(str) );
	return puts( bbTmpCString(str) );
}
Example #15
0
int opendir_( BBString *path ){
	if( _bbusew ) return (int)_wopendir( bbTmpWString(path) );
	return (int)opendir( bbTmpCString(path) );
}
Example #16
0
BBString *bbSystemRequestFile( BBString *text,BBString *exts,int defext,int save,BBString *file,BBString *dir ){

	BBString *str=&bbEmptyString;
	
	if( _usew ){
		wchar_t buf[MAX_PATH];
		OPENFILENAMEW of={sizeof(of)};
		
		wcscpy( buf,bbTmpWString( file ) );

		of.hwndOwner=GetActiveWindow();
		of.lpstrTitle=bbTmpWString( text );
		of.lpstrFilter=bbTmpWString( exts );
		of.nFilterIndex=defext;
		of.lpstrFile=buf;
		of.lpstrInitialDir=dir->length ? bbTmpWString( dir ) : 0;
		of.nMaxFile=MAX_PATH;
		of.Flags=OFN_HIDEREADONLY|OFN_NOCHANGEDIR;
		
		beginPanel();
		if( save ){
			of.lpstrDefExt=L"";
			of.Flags|=OFN_OVERWRITEPROMPT;
			if( GetSaveFileNameW( &of ) ){
				str=bbStringFromWString( buf );
			}
		}else{
			of.Flags|=OFN_FILEMUSTEXIST;
			if( GetOpenFileNameW( &of ) ){
				str=bbStringFromWString( buf );
			}
		}
		endPanel();
	}else{
		char buf[MAX_PATH];
		OPENFILENAMEA of={sizeof(of)};

		strcpy( buf,bbTmpCString( file ) );

		of.hwndOwner=GetActiveWindow();
		of.lpstrTitle=bbTmpCString( text );
		of.lpstrFilter=bbTmpCString( exts );
		of.nFilterIndex=defext;
		of.lpstrFile=buf;
		of.lpstrInitialDir=dir->length ? bbTmpCString( dir ) : 0;
		of.nMaxFile=MAX_PATH;
		of.Flags=OFN_HIDEREADONLY|OFN_NOCHANGEDIR;
		
		beginPanel();
		
		if( save ){
			of.lpstrDefExt="";
			of.Flags|=OFN_OVERWRITEPROMPT;
			if( GetSaveFileNameA( &of ) ){
				str=bbStringFromCString( buf );
			}
		}else{
			of.Flags|=OFN_FILEMUSTEXIST;
			if( GetOpenFileNameA( &of ) ){
				str=bbStringFromCString( buf );
			}
		}
		endPanel();
	}
	return str;
}
Example #17
0
int chdir_( BBString *path ){
	if( _bbusew ) return _wchdir( bbTmpWString(path) );
	return _chdir( bbTmpCString(path) );
}
Example #18
0
int fopen_( BBString *file,BBString *mode ){
	if( _bbusew ) return (int)_wfopen( bbTmpWString(file),bbTmpWString(mode) );
	return (int)fopen( bbTmpCString(file),bbTmpCString(mode) );
}
Example #19
0
void bbStartup( int argc,char *argv[],void *dummy1,void *dummy2 ){

	int i,k;
	BBString **p;
	
	//Start up GC and create bbAppFile, bbAppDir and bbLaunchDir
	
#if _WIN32

	char *ebp;
	OSVERSIONINFO os={ sizeof(os) };
	
	//asm( "movl %%ebp,%0;":"=r"(ebp) );//::"%ebp" );
	
	//bbGCStackTop=ebp+28;
	
	// BaH bbThreadStartup();
	bbGCStartup();

	if( GetVersionEx( &os ) ){
		if( os.dwPlatformId==VER_PLATFORM_WIN32_NT ){
			_bbusew=1;
		}
	}
	
	if( _bbusew ){
		int e=0;
		wchar_t buf[MAX_PATH];
		
		_wgetcwd( buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
		}
		bbLaunchDir=bbStringFromWString( buf );
		
		GetModuleFileNameW( GetModuleHandleW(0),buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
			if( buf[i]=='/' ) e=i;
		}
		bbAppFile=bbStringFromWString( buf );

		if( e ){
			if( buf[e-1]==':' ) ++e;
			bbAppDir=bbStringFromShorts( buf,e );
		}else{
			bbAppDir=&bbEmptyString;
		}

		_wchdir( bbTmpWString( bbAppDir ) );
		
	}else{
		int e=0;
		char buf[MAX_PATH];

		_getcwd( buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
		}
		bbLaunchDir=bbStringFromCString( buf );
		
		GetModuleFileNameA( GetModuleHandleA(0),buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
			if( buf[i]=='/' ) e=i;
		}
		bbAppFile=bbStringFromCString( buf );

		if( e ){
			if( buf[e-1]==':' ) ++e;
			bbAppDir=bbStringFromBytes( buf,e );
		}else{
			bbAppDir=&bbEmptyString;
		}

		_chdir( bbTmpCString( bbAppDir ) );
	}

#elif __linux

	char *ebp;
	char buf[PATH_MAX];
	char lnk[PATH_MAX];
	pid_t pid;
	
	// asm( "movl %%ebp,%0;":"=r"(ebp) );//::"%ebp" );
	
	bbGCStackTop=ebp+28;
	
	// BaH bbThreadStartup();
	bbGCStartup();
	
	getcwd( buf,PATH_MAX );
	bbLaunchDir=bbStringFromUTF8String( buf );
	
	pid=getpid();
	sprintf( lnk,"/proc/%i/exe",pid );
	i=readlink( lnk,buf,PATH_MAX );
	if( i>0 ){
		char *p;
		buf[i]=0;
		bbAppFile=bbStringFromUTF8String( buf );
		p=strrchr( buf,'/' );
		if( p ){
			*p=0;
			bbAppDir=bbStringFromUTF8String( buf );
		}else{
			bbAppDir=&bbEmptyString;
		}
	}else{
		bbAppFile=&bbEmptyString;
		bbAppDir=&bbEmptyString;
	}
	
	chdir( bbTmpUTF8String( bbAppDir ) );
	
#elif __APPLE__
	
	CFURLRef url;
	char buf[PATH_MAX],*e;
	
//#if BB_ARGP
//	bbGCStackTop=bbArgp(0);
//#else
	bbGCStackTop=&argc;
//#endif

	// BaH bbThreadStartup();
	bbGCStartup();
	
	getcwd( buf,PATH_MAX );
	bbLaunchDir=bbStringFromUTF8String( buf );
	
	url=CFBundleCopyExecutableURL( CFBundleGetMainBundle() );
	CFURLGetFileSystemRepresentation( url,true,(UInt8*)buf,PATH_MAX );
	CFRelease( url );
	
	bbAppFile=bbStringFromUTF8String( buf );

	if( e=strstr( buf,".app/Contents/MacOS/" ) ){
		*e=0;
	}
	if( e=strrchr( buf,'/' ) ){
		*e=0;
		bbAppDir=bbStringFromUTF8String( buf );
	}else{
		bbAppDir=&bbEmptyString;
	}
	
	chdir( bbTmpUTF8String( bbAppDir ) );
	
#endif

	BBINCREFS( bbLaunchDir );
	BBINCREFS( bbAppDir );
	BBINCREFS( bbAppFile );

	bbAppTitle=bbStringFromCString( "BlitzMax Application" );
	BBINCREFS( bbAppTitle );

	bbAppArgs=bbArrayNew1D( "$",argc );
	BBINCREFS( bbAppArgs );

	p=(BBString**)BBARRAYDATA( bbAppArgs,1 );
	
	for( k=0;k<argc;++k ){
		BBString *arg=bbStringFromCString( argv[k] );
		BBINCREFS( arg );
		*p++=arg;
	}
	
	startup();
}
Example #20
0
int rename_( BBString *src,BBString *dst ){
	if( _bbusew ) return _wrename( bbTmpWString(src),bbTmpWString(dst) );
	return rename( bbTmpCString(src),bbTmpCString(dst) );
}