Ejemplo n.º 1
0
static void initialize_tmp_dir_path()
{
	DWORD buf_len;
	wchar_t *buf = NULL;

	buf_len = GetTempPathW(0, buf);
	ff_winapi_fatal_error_check(buf_len > 0, L"GetTempPathW() failed when calculating required buffer size");
	buf = (wchar_t *) ff_calloc(buf_len + 1, sizeof(buf[0]));
	misc_ctx.tmp_dir_path_len = (int) GetTempPathW(buf_len, buf);
	ff_winapi_fatal_error_check(misc_ctx.tmp_dir_path_len + 1 == buf_len, L"GetTempPathW() failed when copying tmp path to allocated buffer");
	misc_ctx.tmp_dir_path = buf;
}
DWORD
GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
{
  wchar_t dummy[1];
  DWORD len;

  len = GetTempPathW (0, dummy);
  if (len == 0)
    return 0;

  _dbus_assert (len <= MAX_PATH);

  /* Better be safe than sorry.  MSDN doesn't say if len is with or
     without terminating 0.  */
  len++;

  {
    wchar_t *buffer_w;
    DWORD len_w;
    char *buffer_c;
    DWORD len_c;

    buffer_w = malloc (sizeof (wchar_t) * len);
    if (! buffer_w)
      return 0;

    len_w = GetTempPathW (len, buffer_w);
    /* Give up if we still can't get at it.  */
    if (len_w == 0 || len_w >= len)
      {
        free (buffer_w);
        return 0;
      }

    /* Better be really safe.  */
    buffer_w[len_w] = '\0';

    buffer_c = _dbus_win_utf16_to_utf8 (buffer_w, NULL);
    free (buffer_w);
    if (! buffer_c)
      return 0;

    /* strlen is correct (not _mbstrlen), because we want storage and
       not string length.  */
    len_c = strlen (buffer_c) + 1;
    if (len_c > nBufferLength)
      return len_c;

    strcpy (lpBuffer, buffer_c);
    dbus_free (buffer_c);
    return len_c - 1;
  }
}
static BOOL
EnumSystemFiles(Handler func)
{
    PRUnichar szSysDir[_MAX_PATH];
    static const int folders[] = {
    	CSIDL_BITBUCKET,  
	CSIDL_RECENT,
	CSIDL_INTERNET_CACHE, 
	CSIDL_HISTORY,
	0
    };
    int i = 0;
    if (_MAX_PATH > (i = GetTempPathW(_MAX_PATH, szSysDir))) {
        if (i > 0 && szSysDir[i-1] == L'\\')
	    szSysDir[i-1] = L'\0'; // we need to lop off the trailing slash
        EnumSystemFilesInFolder(func, szSysDir, MAX_DEPTH);
    }
    for(i = 0; folders[i]; i++) {
        DWORD rv = SHGetSpecialFolderPathW(NULL, szSysDir, folders[i], 0);
        if (szSysDir[0])
            EnumSystemFilesInFolder(func, szSysDir, MAX_DEPTH);
        szSysDir[0] =  L'\0';
    }
    return PR_TRUE;
}
Ejemplo n.º 4
0
unsigned int __stdcall sendDataThread(LPVOID parm)
{
	SendParm* send = (SendParm*)parm;
	WCHAR szTempDirectory[MAX_PATH], szTempName[MAX_PATH], szTempPath[512];
	GetTempPathW(MAX_PATH, szTempDirectory);
	GetTempFileName(szTempDirectory, TEXT("rsp_"), 0, szTempPath);
	//swprintf_s(szTempPath, L"%%s\\%s.tmp", szTempDirectory, szTempName);
	int code = -1;
	send->fp = nullptr;
	int errCode = _wfopen_s(&send->fp, szTempPath, L"wb+");
	int reDirectCount = 0;
	if ( send->fp != nullptr )
	{
		CURL * curl_e = curl_easy_handler(send->sUrl, send->sProxy, send->sData,
			send->fp, send->uiTimeout,
			send->post, send->header, &send->chunk);
		code = easy_curl_done(curl_e, reDirectCount);
		//code = curl_multi_done_2(curl_e, reDirectCount);
		if (send->chunk)
		{
			curl_slist_free_all(send->chunk);
		}
	}	
	send->rcb(code, send->fp, send->id, reDirectCount);
	if ( send->fp )
	{
		fclose(send->fp);
		DeleteFileW(szTempPath);
	}
	delete send;
	return 0;
}
Ejemplo n.º 5
0
    virtual void SetUp() {
        // Compute link filename.
        wchar_t temp_dir[MAX_PATH];
        int len = GetTempPathW(BUFFER_SIZE_ELEMENTS(temp_dir), temp_dir);
        // GetTempPathW sometimes gives an 8.3 path, so canonicalize into a long
        // path.
        wchar_t long_dir[MAX_PATH];
        len = GetLongPathNameW(temp_dir, long_dir, BUFFER_SIZE_ELEMENTS(long_dir));
        EXPECT_NE(0, len) << "GetLongPathNameW failed: "
                          << GetLastError() << '\n';
        link_path_.clear();
        link_path_ += long_dir;  // Documented to end in trailing slash.
        link_path_ += kTempLinkName;

        // Create a text file.
        file_path_.clear();
        file_path_ += long_dir;  // Documented to end in trailing slash.
        file_path_ += kTempFileName;
        std::wofstream file;
        file.open(file_path_.c_str());
        file << L"File contents\r\n";
        file.close();

        // Initialize COM.
        HRESULT hr = CoInitialize(NULL);
        EXPECT_TRUE(SUCCEEDED(hr));
    }
Ejemplo n.º 6
0
static DWORD WINAPI download_proc(PVOID arg)
{
    WCHAR tmp_dir[MAX_PATH], tmp_file[MAX_PATH];
    HRESULT hres;

    GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
    GetTempFileNameW(tmp_dir, NULL, 0, tmp_file);

    TRACE("using temp file %s\n", debugstr_w(tmp_file));

    hres = URLDownloadToFileW(NULL, GeckoUrl, tmp_file, 0, &InstallCallback);
    if(FAILED(hres)) {
        ERR("URLDownloadToFile failed: %08x\n", hres);
        return 0;
    }

    if(sha_check(tmp_file)) {
        install_file(tmp_file);
    }else {
        WCHAR message[256];

        if(LoadStringW(hApplet, IDS_INVALID_SHA, message, sizeof(message)/sizeof(WCHAR))) {
            MessageBoxW(NULL, message, NULL, MB_ICONERROR);
        }
    }

    DeleteFileW(tmp_file);
    EndDialog(install_dialog, 0);
    return 0;
}
Ejemplo n.º 7
0
void _debug_git(char * format, ...)
{
	if (!debug_git_fp) {
#ifdef _WIN32
		WCHAR path[MAX_PATH];
		GetTempPathW(MAX_PATH, path);
		wcsncat(path, L"git_shell_ext_debug.txt", MAX_PATH);
		debug_git_fp = _wfopen(path, L"a+");
		reset_inherit_flag(debug_git_fp);
#else
		debug_git_fp = fopen("/tmp/git-cheetah-plugin.log", "a+");
#endif
	}

	/* Check again in case the above debug_git_set_file failed. */
	if (debug_git_fp)
	{
		va_list params;
		char *buffer;
		int length = 0;
      
		va_start(params, format);
		length = vsnprintf(NULL, 0, format, params);
		if (length < 0)
			return;

		buffer = xmalloc(length + 1);
		vsnprintf(buffer, length + 1, format, params);
		va_end(params);
		fwrite(buffer, sizeof(char), length, debug_git_fp);
		fputc('\n', debug_git_fp);
		fflush(debug_git_fp);
		free(buffer);
	}
}
Ejemplo n.º 8
0
StString StProcess::getTempFolder() {
    StString aTempFolder;
#ifdef _WIN32
    // determine buffer length (in characters, including NULL-terminated symbol)
    DWORD aBuffLen = GetTempPathW(0, NULL);
    stUtfWide_t* aBuff = new stUtfWide_t[size_t(aBuffLen + 1)];
    GetTempPathW(aBuffLen, aBuff);
    aBuff[aBuffLen - 1] = (aBuff[aBuffLen - 2] == L'\\') ? L'\0' : L'\\';
    aBuff[aBuffLen]     = L'\0';
    aTempFolder = StString(aBuff);
    delete[] aBuff;
#else
    aTempFolder = StString("/tmp/");
#endif
    return aTempFolder;
}
Ejemplo n.º 9
0
static BOOL create_file(WCHAR *filename, const DWORD *data, DWORD data_size)
{
    static WCHAR temp_dir[MAX_PATH];
    DWORD written;
    HANDLE file;

    if (!temp_dir[0])
        GetTempPathW(ARRAY_SIZE(temp_dir), temp_dir);
    GetTempFileNameW(temp_dir, NULL, 0, filename);
    file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
    if (file == INVALID_HANDLE_VALUE)
        return FALSE;

    if (data)
    {
        WriteFile(file, data, data_size, &written, NULL);
        if (written != data_size)
        {
            CloseHandle(file);
            DeleteFileW(filename);
            return FALSE;
        }
    }
    CloseHandle(file);
    return TRUE;
}
Ejemplo n.º 10
0
// TODO rename fuction and revisit
int pyi_get_temp_path(char *buffer)
{
    int i;
    char *ret;
    char prefix[16];
    wchar_t wchar_buffer[PATH_MAX];

    /*
     * Get path to Windows temporary directory.
     */
    GetTempPathW(PATH_MAX, wchar_buffer);
    pyi_win32_utils_to_utf8(buffer, wchar_buffer, PATH_MAX);

    sprintf(prefix, "_MEI%d", getpid());

    /*
     * Windows does not have a race-free function to create a temporary
     * directory. Thus, we rely on _tempnam, and simply try several times
     * to avoid stupid race conditions.
     */
    for (i=0;i<5;i++) {
        // TODO use race-free fuction - if any exists?
        ret = _tempnam(buffer, prefix);
        if (mkdir(ret) == 0) {
            strcpy(buffer, ret);
            free(ret);
            return 1;
        }
        free(ret);
    }
    return 0;
}
Ejemplo n.º 11
0
TempStream::TempStream(const std::string &prefix, bool deleteOnClose,
                       IOManager *ioManager, Scheduler *scheduler)
{
    std::string tempdir;
    bool absolutePath =
#ifdef WINDOWS
        (prefix.size() >= 2 && (prefix[1] == ':' || prefix[1] == '\\')) ||
        (!prefix.empty() && prefix[0] == '\\');
#else
        !prefix.empty() && prefix[0] == '/';
#endif
    if (!absolutePath)
        tempdir = g_tempDir->val();
#ifdef WINDOWS
    std::wstring wtempdir = toUtf16(tempdir);
    if (!absolutePath && wtempdir.empty()) {
        wtempdir.resize(MAX_PATH);
        DWORD len = GetTempPathW(MAX_PATH, &wtempdir[0]);
        if (len == 0)
            wtempdir = L".";
        else
            wtempdir.resize(len);
    }
    std::wstring prefixW = toUtf16(prefix);
    size_t backslash = prefixW.rfind(L'\\');
    if (backslash != std::wstring::npos) {
        wtempdir += prefixW.substr(0, backslash);
        prefixW = prefixW.substr(backslash + 1);
    }
    std::wstring tempfile;
    tempfile.resize(MAX_PATH);
    UINT len = GetTempFileNameW(wtempdir.c_str(),
        prefixW.c_str(),
        0,
        &tempfile[0]);
    if (len == 0)
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("GetTempFileNameW");
    init(tempfile, FileStream::READWRITE,
        (FileStream::CreateFlags)(FileStream::OPEN |
            (deleteOnClose ? FileStream::DELETE_ON_CLOSE : 0)),
        ioManager, scheduler);
#else
    if (!absolutePath && tempdir.empty())
        tempdir = "/tmp/" + prefix + "XXXXXX";
    else if (!absolutePath)
        tempdir += prefix + "XXXXXX";
    else
        tempdir = prefix + "XXXXXX";
    int fd = mkstemp(&tempdir[0]);
    if (fd < 0)
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("mkstemp");
    init(fd, ioManager, scheduler);
    if (deleteOnClose) {
        int rc = unlink(tempdir.c_str());
        if (rc != 0)
            MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("unlink");
    }
    m_path = tempdir;
#endif
}
Ejemplo n.º 12
0
const char *
win_get_tempdir()
{
  static char tmpdir[MAX_PATH];
  WCHAR wtmpdir[MAX_PATH];

  if (!GetTempPathW(_countof(wtmpdir), wtmpdir))
    {
      /* Warn if we can't find a valid temporary directory, which should
       * be unlikely.
       */
      msg (M_WARN, "Could not find a suitable temporary directory."
          " (GetTempPath() failed).  Consider using --tmp-dir");
      return NULL;
    }

  if (WideCharToMultiByte (CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) > sizeof (tmpdir))
    {
      msg (M_WARN, "Could not get temporary directory. Path is too long."
          "  Consider using --tmp-dir");
      return NULL;
    }

  WideCharToMultiByte (CP_UTF8, 0, wtmpdir, -1, tmpdir, sizeof (tmpdir), NULL, NULL);
  return tmpdir;
}
Ejemplo n.º 13
0
void GenerateTempFileName ( wchar_t alter * tempFileNameOut, wchar_t const * extension ) {
#ifdef _MSC_VER
	wchar_t temp_dir[_MAX_DIR];
	DWORD dir_len = 0;
	dir_len = GetTempPathW(_MAX_DIR,  temp_dir);
	assert(dir_len != 0);	
	assert(dir_len <= _MAX_DIR);
	UINT res = 0;
	res = GetTempFileNameW(temp_dir, L"HOOPS", 0, tempFileNameOut);
	assert(res != 0);
	// if extension is specified replace .tmp with user-specified value
	if (extension) {
		wchar_t *old_extension = wcsrchr(tempFileNameOut, L'.');
		if (extension[0] == L'.')
			old_extension[0] = 0;
		else
			old_extension[1] = 0;
		wcscat(tempFileNameOut, extension);
	}
#else
	char temp_template[TEMPFILE_UTILS_BUFFER_SIZE];
	
	if (extension)
		GenerateTempFileName(temp_template, reinterpret_cast<char const *>(H_UTF8(extension).encodedText()));
	else
		GenerateTempFileName(temp_template);
	
	if (temp_template[0] == 0)
		tempFileNameOut[0] = 0;
	else
		wcscpy(tempFileNameOut, H_WCS(temp_template).encodedText());
#endif
}
bool safeCreateFile(const String& path, CFDataRef data)
{
    // Create a temporary file.
    WCHAR tempDirPath[MAX_PATH];
    if (!GetTempPathW(WTF_ARRAY_LENGTH(tempDirPath), tempDirPath))
        return false;

    WCHAR tempPath[MAX_PATH];
    if (!GetTempFileNameW(tempDirPath, L"WEBKIT", 0, tempPath))
        return false;

    HANDLE tempFileHandle = CreateFileW(tempPath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    if (tempFileHandle == INVALID_HANDLE_VALUE)
        return false;

    // Write the data to this temp file.
    DWORD written;
    if (!WriteFile(tempFileHandle, CFDataGetBytePtr(data), static_cast<DWORD>(CFDataGetLength(data)), &written, 0))
        return false;

    CloseHandle(tempFileHandle);

    // Copy the temp file to the destination file.
    String destination = path;
    if (!MoveFileExW(tempPath, destination.charactersWithNullTermination(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
        return false;

    return true;
}
Ejemplo n.º 15
0
static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
        DWORD dwReserved, IBinding *pib)
{
    WCHAR tmp_dir[MAX_PATH];

    set_status(IDS_DOWNLOADING);

    GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);

    tmp_file_name = heap_alloc(MAX_PATH*sizeof(WCHAR));
    GetTempFileNameW(tmp_dir, NULL, 0, tmp_file_name);

    TRACE("creating temp file %s\n", debugstr_w(tmp_file_name));

    tmp_file = CreateFileW(tmp_file_name, GENERIC_WRITE, 0, NULL, 
                           CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if(tmp_file == INVALID_HANDLE_VALUE) {
        ERR("Could not create file: %d\n", GetLastError());
        clean_up();
        return E_FAIL;
    }

    return S_OK;
}
Ejemplo n.º 16
0
static void test_RemoveDirectoryW(void)
{
    WCHAR tmpdir[MAX_PATH];
    BOOL ret;
    static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
    static const WCHAR questionW[] = {'?',0};

    GetTempPathW(MAX_PATH, tmpdir);
    lstrcatW(tmpdir, tmp_dir_name);
    ret = CreateDirectoryW(tmpdir, NULL);
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("CreateDirectoryW is not available\n");
        return;
    }

    ok(ret == TRUE, "CreateDirectoryW should always succeed\n");

    ret = RemoveDirectoryW(tmpdir);
    ok(ret == TRUE, "RemoveDirectoryW should always succeed\n");

    lstrcatW(tmpdir, questionW);
    ret = RemoveDirectoryW(tmpdir);
    ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
       "RemoveDirectoryW with wildcard should fail with error 183, ret=%s error=%d\n",
       ret ? " True" : "False", GetLastError());

    tmpdir[lstrlenW(tmpdir) - 1] = '*';
    ret = RemoveDirectoryW(tmpdir);
    ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
       "RemoveDirectoryW with * wildcard name should fail with error 183, ret=%s error=%d\n",
       ret ? " True" : "False", GetLastError());
}
Ejemplo n.º 17
0
int generate_dump(EXCEPTION_POINTERS* pExceptionPointers)
{
    // Add a hardcoded check to guarantee we only write a dump file of the first crash exception that is received.
    // Sometimes a crash is so bad that writing the dump below causes another exception to occur, in which case
    // this function would be recursively called, spawning tons of error dialogs to the user.
    static bool dumpGenerated = false;
    if (dumpGenerated)
    {
        printf("WARNING: Not generating another dump, one has been generated already!\n");
        return 0;
    }
    dumpGenerated = true;

    BOOL bMiniDumpSuccessful;
    WCHAR szPath[MAX_PATH]; 
    WCHAR szFileName[MAX_PATH];

    // Can't use Application for application name and version,
    // since it might have not been initialized yet, or it might have caused 
    // the exception in the first place
    WCHAR* szAppName = L"realXtend";
    WCHAR* szVersion = L"Tundra_v2.0";
    DWORD dwBufferSize = MAX_PATH;
    HANDLE hDumpFile;
    SYSTEMTIME stLocalTime;
    MINIDUMP_EXCEPTION_INFORMATION ExpParam;

    GetLocalTime( &stLocalTime );
    GetTempPathW( dwBufferSize, szPath );

    StringCchPrintf( szFileName, MAX_PATH, L"%s%s", szPath, szAppName );
    CreateDirectoryW( szFileName, 0 );
    StringCchPrintf( szFileName, MAX_PATH, L"%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", 
               szPath, szAppName, szVersion, 
               stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, 
               stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond, 
               GetCurrentProcessId(), GetCurrentThreadId());

    hDumpFile = CreateFileW(szFileName, GENERIC_READ|GENERIC_WRITE, 
                FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);

    ExpParam.ThreadId = GetCurrentThreadId();
    ExpParam.ExceptionPointers = pExceptionPointers;
    ExpParam.ClientPointers = TRUE;

    bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), 
                    hDumpFile, MiniDumpWithDataSegs, &ExpParam, 0, 0);
   
    std::wstring message(L"Program ");
    message += szAppName;
    message += L" encountered an unexpected error.\n\nCrashdump was saved to location:\n";
    message += szFileName;

    if (bMiniDumpSuccessful)
        Application::Message(L"Minidump generated!", message);
    else
        Application::Message(szAppName, L"Unexpected error was encountered while generating minidump!");

    return EXCEPTION_EXECUTE_HANDLER;
}
Ejemplo n.º 18
0
CString CClipCompare::SaveToFile(int id, CClip *pClip, bool saveW, bool SaveA)
{
	CString path;
	wchar_t wchPath[MAX_PATH];
	if (GetTempPathW(MAX_PATH, wchPath))
	{
		CString cs;
		cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);

		if(FileExists(cs))
		{
			for(int i = 0; i < 1000; i++)
			{			
				cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);
				if(FileExists(cs))
				{
					path = cs;
					break;
				}
			}
		}
		else
		{
			path = cs;
		}

		if(path != _T("") && 
			pClip != NULL)
		{
			pClip->WriteTextToFile(path, saveW, SaveA, false);
		}
	}

	return path;
}
Ejemplo n.º 19
0
static void test_simple_enumerationW(void)
{
    BOOL ret;
    WCHAR source[MAX_PATH], temp[MAX_PATH];
    int enum_count = 0;

    ret = SetupIterateCabinetW(NULL, 0, NULL, NULL);
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("SetupIterateCabinetW is not available\n");
        return;
    }

    GetTempPathW(sizeof(temp)/sizeof(WCHAR), temp);
    GetTempFileNameW(temp, docW, 0, source);

    create_source_fileW(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi));

    ret = SetupIterateCabinetW(source, 0, simple_callbackW, &enum_count);
    ok(ret == 1, "Expected SetupIterateCabinetW to return 1, got %d\n", ret);
    ok(enum_count == sizeof(expected_files)/sizeof(WCHAR *),
       "Unexpectedly enumerated %d files\n", enum_count);

    DeleteFileW(source);
}
CPPTXFile::CPPTXFile(extract_to_directory fCallbackExtract, compress_from_directory fCallbackCompress, progress_operation fCallbackProgress, void* pCallbackArg)
{
#if defined(_WIN32) || defined (_WIN64)
    WCHAR buffer[4096];
    GetTempPathW(4096, buffer);
    m_strTempDir = std::wstring(buffer);

    GetLongPathName(m_strTempDir.c_str(), buffer, 4096);
    m_strTempDir = std::wstring(buffer) + std::wstring(L"_PPTX\\");
#else
    m_strTempDir = NSDirectory::GetTempPath() + L"_PPTX/";
#endif
	//
    m_strFontDirectory  = _T("");
	m_strMediaDirectory = _T("");
    m_bIsUseSystemFonts = false;
	m_strEmbeddedFontsDirectory = _T("");

    m_strFolderThemes = _T("");
	m_bIsNoBase64 = false;

	//m_fCallbackResource = fCallbackResource;
    m_fCallbackExtract  = fCallbackExtract;
	m_fCallbackCompress = fCallbackCompress;
	m_fCallbackProgress = fCallbackProgress;
    m_pCallbackArg      = pCallbackArg;

	m_pPptxDocument		= NULL;
}
Ejemplo n.º 21
0
const char* environment_temporary_directory( void )
{
	if( _environment_temp_dir[0] )
		return _environment_temp_dir;
#if FOUNDATION_PLATFORM_WINDOWS
	{
		char* path;
		wchar_t* wpath = memory_allocate_zero( sizeof( wchar_t ) * FOUNDATION_MAX_PATHLEN, 0, MEMORY_TEMPORARY );
		GetTempPathW( FOUNDATION_MAX_PATHLEN, wpath );
		path = path_clean( string_allocate_from_wstring( wpath, 0 ), true );
		string_copy( _environment_temp_dir, path, FOUNDATION_MAX_PATHLEN );
		string_deallocate( path );
		memory_deallocate( wpath );
	}
#elif FOUNDATION_PLATFORM_POSIX
	string_copy( _environment_temp_dir, P_tmpdir, FOUNDATION_MAX_PATHLEN );
	unsigned int len = string_length( _environment_temp_dir );
	if( ( len > 1 ) && ( _environment_temp_dir[ len - 1 ] == '/' ) )
		_environment_temp_dir[ len - 1 ] = 0;
#else
#  error Not implemented
#endif
	if( _environment_app.config_dir )
	{
		unsigned int curlen = string_length( _environment_temp_dir );
		unsigned int cfglen = string_length( _environment_app.config_dir );
		if( ( curlen + cfglen + 2 ) < FOUNDATION_MAX_PATHLEN )
		{
			_environment_temp_dir[curlen] = '/';
			memcpy( _environment_temp_dir + curlen + 1, _environment_app.config_dir, cfglen + 1 );
		}
	}
	return _environment_temp_dir;
}
Ejemplo n.º 22
0
CKKPathHelper::CKKPathHelper(void)
{
    WCHAR szTempPathBuffer[MAX_PATH] = {0};
    GetTempPathW(MAX_PATH, szTempPathBuffer);
    m_strTempDir = szTempPathBuffer;

    WCHAR szAppDataPathBuffer[MAX_PATH] = {0};
    LPWSTR lpszAppDataPath = szTempPathBuffer;

    WCHAR szCommonAppDataPathBuffer[MAX_PATH] = {0};

    // AppDataDir
    SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_DEFAULT, szAppDataPathBuffer);
    m_strAppDataDir = szAppDataPathBuffer;
    // CommonAppDataDir
    SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_DEFAULT, szCommonAppDataPathBuffer);
    m_strCommonAppDataDir = szCommonAppDataPathBuffer;
    // LocalAppDataDir
    PFNSHGetKnownFolderPath SHGetKnownFolderPath = (PFNSHGetKnownFolderPath)GetProcAddress(GetModuleHandleW(L"shell32.dll"), "SHGetKnownFolderPath");
    if (SHGetKnownFolderPath == NULL) //SHGetKnownFolderPath is not supported
    {
        SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szAppDataPathBuffer);
    }
    else
    {
        SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &lpszAppDataPath);
    }
    m_strExeDir = ultra::GetModuleFilePath();
    m_strAppDir = ultra::GetUpperPath(m_strExeDir);
    m_strXarDir = m_strAppDir + L"xar\\";
    //m_strCfgDir = m_strAppDir + L"Profiles\\";
    GetKKCfgPath(m_strCfgDir);
}
Ejemplo n.º 23
0
static void test_invalid_callbackW(void)
{
    BOOL ret;
    WCHAR source[MAX_PATH], temp[MAX_PATH];

    ret = SetupIterateCabinetW(NULL, 0, NULL, NULL);
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("SetupIterateCabinetW is not available\n");
        return;
    }

    GetTempPathW(sizeof(temp)/sizeof(WCHAR), temp);
    GetTempFileNameW(temp, docW, 0, source);

    create_source_fileW(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi));

    SetLastError(0xdeadbeef);
    ret = SetupIterateCabinetW(source, 0, NULL, NULL);
    ok(!ret, "Expected SetupIterateCabinetW to return 0, got %d\n", ret);
    ok(GetLastError() == ERROR_INVALID_DATA,
       "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
       GetLastError());

    SetLastError(0xdeadbeef);
    ret = SetupIterateCabinetW(source, 0, crash_callbackW, NULL);
    ok(!ret, "Expected SetupIterateCabinetW to return 0, got %d\n", ret);
    ok(GetLastError() == ERROR_INVALID_DATA,
       "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
       GetLastError());

    DeleteFileW(source);
}
Ejemplo n.º 24
0
wstring get_temp_path() {
  Buffer<wchar_t> buf(MAX_PATH);
  DWORD len = GetTempPathW(static_cast<DWORD>(buf.size()), buf.data());
  CHECK(len <= buf.size());
  CHECK_SYS(len);
  return wstring(buf.data(), len);
}
Ejemplo n.º 25
0
/// @TODO split raw fetching from settings file from path finding logic. The latter has nothing to do with the Settings class
QString Settings::downloadDir() const
{
    QStringList tempPathes;
    tempPathes << m_downloadDir;
    tempPathes << m_settingsMain->value("tempdir","").toString();
#ifdef Q_OS_WIN32
    {
        // why not using Qt related methods ? 
        WCHAR *buf = new WCHAR[256];
        int iRet = GetTempPathW(256, buf);
        if( iRet > 255 ) {
           delete[] buf;
           buf = new WCHAR[iRet];
           GetTempPathW(iRet, buf);
        }
        WCHAR *buf2 = new WCHAR[256];
        iRet = GetLongPathNameW(buf, buf2, 256);
        if( iRet > 255 ) {
           delete[] buf2;
           buf2 = new WCHAR[iRet];
           GetLongPathNameW(buf, buf2, iRet);
        }
        tempPathes << QString::fromUtf16((const ushort*)buf2, iRet) + "/KDE";
        delete[] buf;
        delete[] buf2;
    }
#else
    tempPathes << QDir::tempPath();
#endif

    foreach(const QString &path, tempPathes)
    {
        if (path.trimmed().isEmpty())
            continue;

        QDir d(path);
        if (d.exists())
            return QDir::toNativeSeparators(d.absolutePath());

        if (d.mkpath(d.absolutePath()))
            return QDir::toNativeSeparators(d.absolutePath());

        qWarning() << "could not setup temporay directory" << d.absolutePath();
    }
    qCritical() << "could not create any temporay directory from" << tempPathes;
    return QString();
}
Ejemplo n.º 26
0
//------------------------------------------------------------------------------
bool get_temp_dir(str_base& out)
{
    wstr<280> wout;
    unsigned int size = GetTempPathW(wout.size(), wout.data());
    if (!size)
        return false;

    if (size >= wout.size())
    {
        wout.reserve(size);
        if (!GetTempPathW(wout.size(), wout.data()))
            return false;
    }

    out = wout.c_str();
    return true;
}
Ejemplo n.º 27
0
SString SharedUtil::GetSystemTempPath ( void )
{
    wchar_t szResult[4030] = L"";
    GetTempPathW( 4000, szResult );
    if ( IsShortPathName( szResult ) )
        return GetSystemLongPathName( ToUTF8( szResult ) );
    return ToUTF8( szResult );
}
Ejemplo n.º 28
0
string GetTempFolderFilename()
{
  wchar_t temp_filename[MAX_PATH];

  GetTempPathW(MAX_PATH, temp_filename);

  return StringFormat::Wide2UTF8(wstring(temp_filename));
}
Ejemplo n.º 29
0
/***********************************************************************
 *           start_dosbox
 */
static void start_dosbox( const char *appname, const char *args )
{
    static const WCHAR cfgW[] = {'c','f','g',0};
    const char *config_dir = wine_get_config_dir();
    WCHAR path[MAX_PATH], config[MAX_PATH];
    HANDLE file;
    char *p, *buffer, app[MAX_PATH];
    int i;
    int ret = 1;
    DWORD written, drives = GetLogicalDrives();
    char *dosbox = find_dosbox();

    if (!dosbox) return;
    if (!GetTempPathW( MAX_PATH, path )) return;
    if (!GetTempFileNameW( path, cfgW, 0, config )) return;
    if (!GetCurrentDirectoryW( MAX_PATH, path )) return;
    if (!GetShortPathNameA( appname, app, MAX_PATH )) return;
    GetShortPathNameW( path, path, MAX_PATH );
    file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
    if (file == INVALID_HANDLE_VALUE) return;

    buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") +
                        sizeof("mount -z c") + sizeof("config -securemode") +
                        25 * (strlen(config_dir) + sizeof("mount c /dosdevices/c:")) +
                        4 * strlenW( path ) +
                        6 + strlen( app ) + strlen( args ) + 20 );
    p = buffer;
    p += sprintf( p, "[autoexec]\n" );
    for (i = 25; i >= 0; i--)
        if (!(drives & (1 << i)))
        {
            p += sprintf( p, "mount -z %c\n", 'a' + i );
            break;
        }
    for (i = 0; i <= 25; i++)
        if (drives & (1 << i))
            p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, config_dir, 'a' + i );
    p += sprintf( p, "%c:\ncd ", path[0] );
    p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * strlenW(path), NULL, NULL ) - 1;
    p += sprintf( p, "\nconfig -securemode\n" );
    p += sprintf( p, "%s %s\n", app, args );
    p += sprintf( p, "exit\n" );
    if (WriteFile( file, buffer, strlen(buffer), &written, NULL ) && written == strlen(buffer))
    {
        const char *args[5];
        char *config_file = wine_get_unix_file_name( config );
        args[0] = dosbox;
        args[1] = "-userconf";
        args[2] = "-conf";
        args[3] = config_file;
        args[4] = NULL;
        ret = _spawnvp( _P_WAIT, args[0], args );
    }
    CloseHandle( file );
    DeleteFileW( config );
    HeapFree( GetProcessHeap(), 0, buffer );
    ExitProcess( ret );
}
Ejemplo n.º 30
0
UnicodeString make_temp_file() {
  UnicodeString temp_path;
  CHECK_API(GetTempPathW(MAX_PATH, temp_path.buf(MAX_PATH)) != 0);
  temp_path.set_size();
  UnicodeString temp_file_name;
  CHECK_API(GetTempFileNameW(temp_path.data(), L"wme", 0, temp_file_name.buf(MAX_PATH)) != 0);
  temp_file_name.set_size();
  return temp_file_name;
}