示例#1
0
        std::string ResolveIgniteHome(const std::string& path)
        {
            // 1. Check passed argument.
            if (IsValidDirectory(path))
                return path;

            // 2. Check environment variable.
            std::string home = GetEnv(IGNITE_HOME);

            if (IsValidDirectory(home))
                return home;

            // 3. Check current work dir.
            DWORD curDirLen = GetCurrentDirectoryA(0, NULL);

            if (!curDirLen)
                return std::string();

            FixedSizeArray<char> curDir(curDirLen);

            curDirLen = GetCurrentDirectoryA(curDir.GetSize(), curDir.GetData());

            if (!curDirLen)
                return std::string();

            std::string curDirStr(curDir.GetData());

            return ResolveIgniteHome0(curDirStr);
        }
示例#2
0
/// Switches you into a working directory
void Window::cd( char *path )
{
  if( !path )
  {
    error( "You can't change directory to NULL, nothing done" ) ;
    return ;
  }

  // Save the current directory to the stack
  char *cwd = (char*)malloc( MAX_PATH ) ;
  GetCurrentDirectoryA( MAX_PATH, cwd ) ;
  directories.push( cwd ) ;
  
  if( !SetCurrentDirectoryA( path ) )
  {
    error( "Couldn't switch directory to %s", path ) ;
  }
  else
  {
    // This verifies the cd command worked
    char nowDir[MAX_PATH];
    GetCurrentDirectoryA( MAX_PATH, nowDir ) ;
    info( "Current working directory is '%s'", nowDir ) ;
  }
}
示例#3
0
cv::String getcwd()
{
    CV_INSTRUMENT_REGION();
    cv::AutoBuffer<char, 4096> buf;
#if defined WIN32 || defined _WIN32 || defined WINCE
#ifdef WINRT
    return cv::String();
#else
    DWORD sz = GetCurrentDirectoryA(0, NULL);
    buf.allocate((size_t)sz);
    sz = GetCurrentDirectoryA((DWORD)buf.size(), buf.data());
    return cv::String(buf.data(), (size_t)sz);
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
    for(;;)
    {
        char* p = ::getcwd(buf.data(), buf.size());
        if (p == NULL)
        {
            if (errno == ERANGE)
            {
                buf.allocate(buf.size() * 2);
                continue;
            }
            return cv::String();
        }
        break;
    }
    return cv::String(buf.data(), (size_t)strlen(buf.data()));
#else
    return cv::String();
#endif
}
示例#4
0
static ULONG_ADDR CALLBACK GetModuleBase(HANDLE hProcess, ULONG_ADDR dwAddress)
{
    MEMORY_BASIC_INFORMATION memoryInfo;
    ULONG_ADDR dwAddrBase = SymGetModuleBase(hProcess, dwAddress);
    if (dwAddrBase) {
        return dwAddrBase;
    }
    if (VirtualQueryEx(hProcess, (void*)(GC_ULONG_PTR)dwAddress, &memoryInfo,
                       sizeof(memoryInfo))) {
        char filePath[_MAX_PATH];
        char curDir[_MAX_PATH];
        char exePath[_MAX_PATH];
        DWORD size = GetModuleFileNameA((HINSTANCE)memoryInfo.AllocationBase,
                                        filePath, sizeof(filePath));

        /* Save and restore current directory around SymLoadModule, see KB  */
        /* article Q189780.                                                 */
        GetCurrentDirectoryA(sizeof(curDir), curDir);
        GetModuleFileNameA(NULL, exePath, sizeof(exePath));
#if defined(_MSC_VER) && _MSC_VER == 1200
        /* use strcat for VC6 */
        strcat(exePath, "\\..");
#else
        strcat_s(exePath, sizeof(exePath), "\\..");
#endif /* _MSC_VER >= 1200 */
        SetCurrentDirectoryA(exePath);
#ifdef _DEBUG
        GetCurrentDirectoryA(sizeof(exePath), exePath);
#endif
        SymLoadModule(hProcess, NULL, size ? filePath : NULL, NULL,
                      (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase, 0);
        SetCurrentDirectoryA(curDir);
    }
    return (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase;
}
示例#5
0
/* take a path with a drive letter, possibly relative, and return a full path
 * without the drive letter.  This is the full path relative to the working
 * dir for that drive letter.  The input and output paths can be the same.
 */
long fs_GetFullPath(char *pathp, char *outPathp, long outSize)
{
	char tpath[1000];
	char origPath[1000];
    char *firstp;
    long code;
    int pathHasDrive;
    int doSwitch;
    char newPath[3];

	if (pathp[0] != 0 && pathp[1] == ':') {
		/* there's a drive letter there */
        firstp = pathp+2;
        pathHasDrive = 1;
    } else {
        firstp = pathp;
		pathHasDrive = 0;
	}

    if (*firstp == '\\' || *firstp == '/') {
		/* already an absolute pathname, just copy it back */
        strcpy(outPathp, firstp);
        return 0;
    }

    GetCurrentDirectoryA(sizeof(origPath), origPath);

	doSwitch = 0;
    if (pathHasDrive && (*pathp & ~0x20) != (origPath[0] & ~0x20)) {
		/* a drive has been specified and it isn't our current drive.
         * to get path, switch to it first.  Must case-fold drive letters
         * for user convenience.
         */
		doSwitch = 1;
        newPath[0] = *pathp;
        newPath[1] = ':';
        newPath[2] = 0;
        if (!SetCurrentDirectoryA(newPath)) {
			code = GetLastError();
            return code;
        }
    }

    /* now get the absolute path to the current wdir in this drive */
    GetCurrentDirectoryA(sizeof(tpath), tpath);
    strcpy(outPathp, tpath+2);	/* skip drive letter */
	/* if there is a non-null name after the drive, append it */
	if (*firstp != 0) {
        strcat(outPathp, "\\");
        strcat(outPathp, firstp);
	}

	/* finally, if necessary, switch back to our home drive letter */
    if (doSwitch) {
        SetCurrentDirectoryA(origPath);
    }

    return 0;
}
path current_path() {
	std::vector<char> buffer(GetCurrentDirectoryA(0, NULL));
	DWORD length = GetCurrentDirectoryA(buffer.size(), &buffer.front());
	if(length == 0 || length + 1 >= buffer.size()) {
		buffer[0] = '\0';
	}
	return path(&buffer.front());
}
示例#7
0
/*
* Get local current directory. Returns a string which must be
* freed.
*/
char *psftp_getcwd(void)
{
   char *ret = snewn(256, char);
   int len = GetCurrentDirectoryA(256, ret);
   if (len > 256)
      ret = sresize(ret, len, char);
   GetCurrentDirectoryA(len, ret);
   return ret;
}
示例#8
0
std::string CurrentDirectory(void) {
    DWORD bufferLength = 0;
    bufferLength = GetCurrentDirectoryA(0, NULL);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    std::string buffer(bufferLength - 1, '0');
    bufferLength = GetCurrentDirectoryA(bufferLength, &buffer[0]);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    return buffer;
}
示例#9
0
char* iupdrvGetCurrentDirectory(void)
{
  char* cur_dir = NULL;

  int len = GetCurrentDirectoryA(0, NULL);
  if (len == 0) return NULL;

  cur_dir = iupStrGetMemory(len + 2);
  GetCurrentDirectoryA(len + 1, cur_dir);
  cur_dir[len] = '\\';
  cur_dir[len + 1] = 0;

  return cur_dir;
}
示例#10
0
/** Implement the Lua function GetCurrentDirectory().
 * 
 * Discover the current directory name and return it to the caller.
 * 
 * \todo There is a low-probability memory leak here. The buffer used 
 * to hold the current directory string came from malloc() and is held 
 * across a call to lua_pushlstring() which can potentially throw an
 * error, which will leak the allocated buffer. The other bits of Win32
 * API wrappers could have similar issues, and should be inspected.
 * 
 * \param L Lua state context for the function.
 * \returns The number of values on the Lua stack to be returned
 * to the Lua caller.
 */
static int dbgGetCurrentDirectory(lua_State *L)
{
	char *buf = 0;
	DWORD len = 0;
	len = GetCurrentDirectoryA(0,NULL);
	if (!len)
		return luaL_error(L, "GetCurrentDirectory failed (%d)", GetLastError());
	buf = malloc(len+1);
	if (!buf)
		return luaL_error(L,"GetCurrentDirectory can't allocate %ld chars", len);
	GetCurrentDirectoryA(len+1, buf);
	lua_pushlstring(L, buf, len);
	free(buf);
	return 1;
}
void CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04_bad()
{
    if(STATIC_CONST_TRUE)
    {
        {
            char path[BAD_PATH_SIZE];
            DWORD length;
            length = GetCurrentDirectoryA(BAD_PATH_SIZE, path);
            if (length == 0 || length >= BAD_PATH_SIZE) /* failure conditions for this API call */
            {
                exit(1);
            }
            /* FLAW: PathAppend assumes the 'path' parameter is MAX_PATH */
            /* INCIDENTAL: CWE 121 stack based buffer overflow, which is intrinsic to
             * this example identified on the CWE webpage */
            if (!PathAppendA(path, "AAAAAAAAAAAA"))
            {
                exit(1);
            }
            printSizeTLine(strlen(path));
            printIntLine(BAD_PATH_SIZE);
            printLine(path);
        }
    }
}
示例#12
0
int
is_a_valid_directory(char* pcszDirectory){
#ifndef WIN32
	struct stat	statbuf;

	if ( pcszDirectory[0] == '\0' )
		return 0;
	
	lstat(pcszDirectory, &statbuf);

	if (S_ISDIR(statbuf.st_mode) == 1){
		return 1;
	}

	write_log(LT_BOTH, "Error: %s is not a valid path!\n", pcszDirectory);
	return 0;
#else
	char		szPath[MAX_PATH];
	int			nRet = 0;

    GetCurrentDirectoryA(MAX_PATH, szPath);
    if ( SetCurrentDirectoryA(pcszDirectory) )
		nRet = 1;
	
    SetCurrentDirectoryA(szPath);
	if ( nRet == 0 )
		write_log(LT_BOTH, "Error: %s is not a valid path!\n",
		pcszDirectory);

	return nRet;
#endif //WIN32
}
示例#13
0
文件: path.c 项目: howard5888/wineT
/* Routine to test that SetCurrentDirectory behaves as expected. */
static void test_setdir(CHAR *olddir,CHAR *newdir,
                        CHAR *cmprstr, INT pass, const CHAR *errstr)
{
  CHAR tmppath[MAX_PATH], *dirptr;
  DWORD val,len,chklen;

  val=SetCurrentDirectoryA(newdir);
  len=GetCurrentDirectoryA(MAX_PATH,tmppath);
/* if 'pass' then the SetDirectoryA was supposed to pass */
  if(pass) {
    dirptr=(cmprstr==NULL) ? newdir : cmprstr;
    chklen=lstrlenA(dirptr);
    ok(val,"%s: SetCurrentDirectoryA failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(lstrcmpiA(dirptr,tmppath)==0,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(SetCurrentDirectoryA(olddir),
       "%s: Couldn't set directory to it's original value\n",errstr);
  } else {
/* else thest that it fails correctly */
    chklen=lstrlenA(olddir);
    ok(val==0,
       "%s: SetCurrentDirectoryA passed when it should have failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
    ok(lstrcmpiA(olddir,tmppath)==0,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
  }
}
示例#14
0
// Get current drive prefix "a:", if any
// This is the same method as used in VC++ CRT.
FXString FXSystem::getCurrentDrive(){
#ifdef WIN32
  FXchar buffer[MAXPATHLEN];
  if(GetCurrentDirectoryA(MAXPATHLEN,buffer) && Ascii::isLetter((FXuchar)buffer[0]) && buffer[1]==':') return FXString(buffer,2);
#endif
  return FXString::null;
  }
示例#15
0
bool getIniValue(string filename,string section,string key,string defultValue,string& value){
	

	char lpBuffer[PATH_BUFFER_LENGTH];
	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	DWORD nBufferLength = GetCurrentDirectoryA(
									PATH_BUFFER_LENGTH,
									lpBuffer
								);
	string path = ""; 
	if (!nBufferLength) return false;

	path=lpBuffer;
	path+="\\";
	path+=filename;
	

	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	nBufferLength=  GetPrivateProfileStringA(						  
						  section.c_str(),
						  key.c_str(),
						  defultValue.c_str(),
						  lpBuffer,
						  PATH_BUFFER_LENGTH,
						  path.c_str()
						);

	if (!nBufferLength) return false;

	value = lpBuffer;
	return true;

}
示例#16
0
static void
win32_add_one_solib (const char *name, CORE_ADDR load_addr)
{
  char buf[MAX_PATH + 1];
  char buf2[MAX_PATH + 1];

#ifdef _WIN32_WCE
  WIN32_FIND_DATA w32_fd;
  WCHAR wname[MAX_PATH + 1];
  mbstowcs (wname, name, MAX_PATH);
  HANDLE h = FindFirstFile (wname, &w32_fd);
#else
  WIN32_FIND_DATAA w32_fd;
  HANDLE h = FindFirstFileA (name, &w32_fd);
#endif

  /* The symbols in a dll are offset by 0x1000, which is the
     offset from 0 of the first byte in an image - because
     of the file header and the section alignment. */
  load_addr += 0x1000;

  if (h == INVALID_HANDLE_VALUE)
    strcpy (buf, name);
  else
    {
      FindClose (h);
      strcpy (buf, name);
#ifndef _WIN32_WCE
      {
	char cwd[MAX_PATH + 1];
	char *p;
	if (GetCurrentDirectoryA (MAX_PATH + 1, cwd))
	  {
	    p = strrchr (buf, '\\');
	    if (p)
	      p[1] = '\0';
	    SetCurrentDirectoryA (buf);
	    GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p);
	    SetCurrentDirectoryA (cwd);
	  }
      }
#endif
    }

#ifndef _WIN32_WCE
  if (strcasecmp (buf, "ntdll.dll") == 0)
    {
      GetSystemDirectoryA (buf, sizeof (buf));
      strcat (buf, "\\ntdll.dll");
    }
#endif

#ifdef __CYGWIN__
  cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2, sizeof (buf2));
#else
  strcpy (buf2, buf);
#endif

  loaded_dll (buf2, load_addr);
}
示例#17
0
bool ShowOpenFileDialog(char* FileName, int FileNameLength, char* filter)
// Open a dialog for selecting a file and returns true if succeeded with the name of the file in the preallocated buffer <FileName>
{
    OPENFILENAMEA ofn ;

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = GetActiveWindow(); 
    ofn.lpstrDefExt = 0;
    FileName[0] = '\0';
	ofn.lpstrFile = FileName;
    ofn.nMaxFile = FileNameLength;
    ofn.lpstrFilter = filter; 
    ofn.nFilterIndex = 1;
    char strAux[MAX_PATH];
	GetCurrentDirectoryA(MAX_PATH, strAux);
	ofn.lpstrInitialDir = strAux;
    ofn.lpstrTitle = LPSTR("Open File");
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ENABLESIZING;

    GetOpenFileNameA(&ofn);

    if (strlen(ofn.lpstrFile) == 0) return false;
    return true;
} // ShowOpenFileDialog
示例#18
0
void injectThread(const wchar_t *processName) {
	while (true) {
		// Wait for process to load.
		wprintf(L"Waiting for %s to load...\n", processName);
		DWORD dwProcessId = NULL;
		do {
			Sleep(10);
			dwProcessId = getProcessId(processName);
		} while (dwProcessId == NULL);

		// Attempt to inject DLL.
		char dllFile[MAX_PATH];
		GetCurrentDirectoryA(sizeof(dllFile), dllFile);
		sprintf(dllFile, "%s\\..\\Hook\\bin\\Hook.dll", dllFile);
		printf("Found PID %d, attempting to inject DLL... ", dwProcessId);
		if (injectDll(dwProcessId, dllFile)) {
			printf("done!\n");
		}

		// Now wait for it to unload.
		do {
			Sleep(10);
			dwProcessId = getProcessId(processName);
		} while (dwProcessId != NULL);
	}
}
示例#19
0
void PlatformChangeDirectoryToResources()
{
	char buffer[MAX_PATH];
	GetCurrentDirectoryA(MAX_PATH, buffer);
	lstrcatA(buffer, TEXT("\\.."));
	SetCurrentDirectoryA(buffer);
}
示例#20
0
static void test_define_dos_deviceA(void)
{
    char drivestr[3];
    char buf[MAX_PATH];
    DWORD ret;

    /* Find an unused drive letter */
    drivestr[1] = ':';
    drivestr[2] = 0;
    for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
        ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
        if (!ret) break;
    }
    if (drivestr[0] > 'z') {
        skip("can't test creating a dos drive, none available\n");
        return;
    }

    /* Map it to point to the current directory */
    ret = GetCurrentDirectoryA(sizeof(buf), buf);
    ok(ret, "GetCurrentDir\n");

    ret = DefineDosDeviceA(0, drivestr, buf);
    todo_wine
    ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);

    if (!ret) {
        skip("can't test removing fake drive\n");
    } else {
	ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
	ok(ret, "Could not remove fake drive %s!\n", drivestr);
    }
}
/* good1() uses if(STATIC_CONST_FALSE) instead of if(STATIC_CONST_TRUE) */
static void good1()
{
    if(STATIC_CONST_FALSE)
    {
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
    }
    else
    {
        {
            /* FIX: ensure MAX_PATH allocated in 'path' */
            char path[MAX_PATH];
            DWORD length;
            length = GetCurrentDirectoryA(MAX_PATH, path);
            if (length == 0 || length >= MAX_PATH)
            {
                exit(1); /* failure conditions for this API call */
            }
            if (!PathAppendA(path, "AAAAAAAAAAAA"))
            {
                exit(1);
            }
            printLine(path);
        }
    }
}
示例#22
0
void BotCfg_OnSave( HWND hDlg, BotCfgDlgSt *st )
{
    // change subdir to '.\configs'
    char curDir[256] = {0};
    char newDir[256] = {0};
    GetCurrentDirectoryA( 200, curDir );
    wsprintfA( newDir, "%s\\configs", curDir );
    SetCurrentDirectoryA( newDir );
    //
    char fileName[256] = {0};
    OPENFILENAMEA ofn;
    memset( &ofn, 0, sizeof(ofn) );
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hDlg;
    ofn.hInstance = g_hInst;
    ofn.lpstrFilter = "Config files\0*.config\0All files\0*.*\0\0";
    ofn.lpstrFile = fileName;
    ofn.nMaxFile = 255;
    ofn.lpstrTitle = "Куда сохранять?";
    ofn.lpstrInitialDir = newDir;
    ofn.Flags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    if( GetSaveFileNameA( &ofn ) )
    {
        if( strstr( fileName, ".config" ) == NULL ) strcat( fileName, ".config" );
        if( !st->myCfg.saveConfig( fileName ) )
        {
            MessageBox( hDlg, TEXT("Конфиг не сохранился!"), TEXT("Ашыпка!"), MB_ICONSTOP );
        }
    }
    // restore cur dir (required to load maps, for example)
    SetCurrentDirectoryA( curDir );
}
示例#23
0
	KeziaResourceManager::KeziaResourceManager(ResourceManagerMode mode)
		:	m_Mode(mode),
			m_PreferredResourceManager(nullptr),
			m_SecondaryResourceManager(nullptr)
	{
		char tmp[255];
		GetCurrentDirectoryA(255, tmp);
		std::string currentDirectory(tmp);

		switch(m_Mode)
		{
		case PreferData:
			m_SecondaryResourceManager = new zlib_ResourceManager();
			m_SecondaryResourceManager->AddSourceDirectory(currentDirectory + "\\Data.zip");
		case DataOnly:
			m_PreferredResourceManager = new Windows_ResourceManager();
			m_PreferredResourceManager->AddSourceDirectory(currentDirectory + "\\Data");
			break;

		case PreferArchive:
			m_SecondaryResourceManager = new Windows_ResourceManager();
			m_SecondaryResourceManager->AddSourceDirectory(currentDirectory + "\\Data");
		case ArchiveOnly:
			m_PreferredResourceManager = new zlib_ResourceManager();
			m_PreferredResourceManager->AddSourceDirectory(currentDirectory + "\\Data.zip");
			break;
		}
	}
示例#24
0
int main(int argc, char *argv[])
{
 #ifdef __WIN32
    // Create the application's console
    if ( AllocConsole() == 0 ) {
       ::MessageBox( 0, L"Can't allocate console!\n", L"** FCS_analyzer **", MB_OK | MB_ICONSTOP );
       return false;
     }

    //(?) add better error handling code later...   freopen( "CON", "w", stderr);
    freopen( "CON", "w", stdout);
//    std::ios::sync_with_stdio();
 
    // This is often nifty to know...
    char* cwd = new char[ MAX_PATH + 1 ];
    GetCurrentDirectoryA( MAX_PATH, cwd );
    std::cout << "CWD = " << cwd << std::endl;
    delete [] cwd;
 #endif //__WIN32

    //QApplication a(argc, argv);
    QApplication app(argc, argv);

    Program * okno = new Program;
    okno->show();

    app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    int app_rv = app.exec();

    return app_rv;
}
示例#25
0
            std::string ResolveIgniteHome(const std::string* path, bool* found)
            {
                if (path)
                    // 1. Check passed argument.
                    return ResolveIgniteHome0(*path, false, found);
                else
                {
                    // 2. Check environment variable.
                    bool envFound;
                    std::string env = GetEnv(IGNITE_HOME, &envFound);

                    if (envFound)
                        return ResolveIgniteHome0(env, false, found);

                    // 3. Check current work dir.
                    const DWORD curDirLen = GetCurrentDirectory(0, NULL);
                        
                    char* curDir = new char[curDirLen];

                    GetCurrentDirectoryA(curDirLen, curDir);

                    std::string curDirStr = curDir;

                    delete[] curDir;

                    return ResolveIgniteHome0(curDirStr, true, found);
                }
            }
示例#26
0
static void create_test_files(void)
{
    int len;

    GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
    len = lstrlenA(CURR_DIR);

    if(len && (CURR_DIR[len-1] == '\\'))
        CURR_DIR[len - 1] = 0;

    get_program_files_dir(PROG_FILES_DIR);

    CreateDirectoryA("msitest", NULL);
    create_file("msitest\\one.txt");
    CreateDirectoryA("msitest\\first", NULL);
    create_file("msitest\\first\\two.txt");
    CreateDirectoryA("msitest\\second", NULL);
    create_file("msitest\\second\\three.txt");

    create_file("four.txt");
    create_file("five.txt");
    create_cab_file("msitest.cab");

    DeleteFileA("four.txt");
    DeleteFileA("five.txt");
}
示例#27
0
/*
	AddPackagePath().

*/
static int c_AddPackagePath( lua_State *_pState )
{
	const char *packagePath = luaL_checkstring( _pState, 1 );

	bool bRelative = true;

	if( lua_isboolean( _pState, 2 ) )
		if( lua_toboolean( _pState, 2 ) == 0 )
			bRelative = false;

	char  dirBuf[ MAX_PATH + 1];
#if defined(WIN32) && defined(_MSC_VER)
	std::string dir;
	if (GetCurrentDirectoryA(sizeof(dirBuf) - 1, dirBuf))
		dir = dirBuf;
#else
	std::string dir = getcwd( &dirBuf[0], MAX_PATH + 1 );
#endif

	if( bRelative )
		dir += packagePath;
	else
		dir = packagePath;

	Call( _pState, "AddInstallation", "s", (const char *)dir.c_str() );

	return( 0 );
}
示例#28
0
void readIniFile()
{
	char Buffer[128];
	char iniFilePath[MAX_PATH];
	GetCurrentDirectoryA(sizeof(iniFilePath), iniFilePath);
	lstrcatA(iniFilePath, "\\multidisk_speed.ini");

	IPC_getPrivateProfileString("Option", "DriveCnt", "1", Buffer, sizeof(Buffer), iniFilePath);
	driveCnt = atoi(Buffer);

	for (int i = 0; i < driveCnt; i++)
	{
		sprintf(Buffer, "DriveName%d", i);
		IPC_getPrivateProfileString("Option", Buffer, "\\\\.\\H:", driveName[i], sizeof(driveName[i]), iniFilePath);
	}

	IPC_getPrivateProfileString("Option", "DriveFlag", "0", Buffer, sizeof(Buffer), iniFilePath);
	drvFlg = atoi(Buffer);

	for (int i = 0; i < driveCnt; i++)
	{
		sprintf(Buffer, "FullFileName%d", i);
		IPC_getPrivateProfileString("Option", Buffer, "data.bin", fileName[i], sizeof(fileName[i]), iniFilePath);
	}

	IPC_getPrivateProfileString("Option", "BufferSizeInMb", "1", Buffer, sizeof(Buffer), iniFilePath);
	bBufSize = atoi(Buffer) * 1024 * 1024;
	IPC_getPrivateProfileString("Option", "BufferNum", "1", Buffer, sizeof(Buffer), iniFilePath);
	bufCnt = atoi(Buffer);
	IPC_getPrivateProfileString("Option", "BufferStatistic", "0", Buffer, sizeof(Buffer), iniFilePath);
	bufStat = atoi(Buffer);
}
string_t SaveFileDialog(const char *title, const char *filter) {
	OPENFILENAMEA ofn;
	char szPath[MAX_PATH];
	char szFile[MAX_PATH];

	memset(&ofn, 0, sizeof(ofn));
	memset(szPath, 0, sizeof(szPath));
	memset(szFile, 0, sizeof(szFile));

	GetCurrentDirectoryA(MAX_PATH, szPath);

	char *fixuped_filter = fixup_filter(filter);

	ofn.lStructSize = sizeof(OPENFILENAMEA);
	ofn.hwndOwner = NULL;
	ofn.lpstrInitialDir = szPath;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrFilter = fixuped_filter;
	ofn.lpstrTitle = title;
	ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;

	if (GetSaveFileNameA(&ofn)) {
		free(fixuped_filter);
		return String.Create(szFile);
	} else {
		free(fixuped_filter);
		return String.Create(NULL);
	}
}
示例#30
0
Options::Options() {
    char directory[MAX_PATH];
    
    configPath = "";
    GetCurrentDirectoryA(MAX_PATH, directory);
    configPath.append(directory).append("\\config.ini");
}