Пример #1
0
    bool BackupTaskState(void) throw()
    {
        CPath path;
        bool bRet = false;

        if (GetIniFile(path))
        {
            CString temp;
            bRet = true;

            // get storage name
            if (GetConfigString(temp, path, _T("storage"), STORAGE_NAME))
            {
                path.RemoveFileSpec();
                path.Append(temp);

                if (path.FileExists())
                {
                    temp = (LPCTSTR)path; // store existing
                    path.RenameExtension(_T(".bak"));
                    bRet = (::MoveFileEx(temp, path, MOVEFILE_REPLACE_EXISTING) != 0);
                } 
            }
        }
        return bRet;
    }
Пример #2
0
LPCTSTR UtilGetTempPath()
{
	static CPath s_tempPath;
	if(_tcslen(s_tempPath)==0){		//初期設定
		//環境変数取得
		std::map<stdString,stdString> envs;
		UtilGetEnvInfo(envs);
		if(!has_key(envs,_T("TMP")) && !has_key(envs,_T("TEMP"))){
			//%TMP%/%TEMP%が存在しなければ自前の一時フォルダを使う(C:\Users\xxx\AppData\Roaming\LhaForge\temp)
			TCHAR szPath[_MAX_PATH+1]={0};
			SHGetFolderPath(NULL,CSIDL_APPDATA|CSIDL_FLAG_CREATE,NULL,SHGFP_TYPE_CURRENT,szPath);
			s_tempPath=szPath;
			s_tempPath.Append(_T("lhaforge\\temp\\"));
			UtilMakeSureDirectoryPathExists(s_tempPath);
		}else{
			//通常のパス
			std::vector<TCHAR> buffer(GetTempPath(0,NULL)+1);
			GetTempPath(buffer.size(),&buffer[0]);
			buffer.back()=_T('\0');
			s_tempPath=&buffer[0];
			s_tempPath.AddBackslash();
		}
	}
	return s_tempPath;
}
Пример #3
0
static CString CombinePath(CPath p, CString fn)
{
    if (fn.Find(':') >= 0 || fn.Find(_T("\\")) == 0) {
        return fn;
    }
    p.Append(CPath(fn));
    return (LPCTSTR)p;
}
Пример #4
0
    int ReadConfig(void) throw()
    {
        CPath path;

        if (GetIniFile(path))
        {
            int f = ::GetPrivateProfileInt(_T("server"), _T("family"), 0, path);
            m_family = (f == 4)? AF_INET : (f == 6)? AF_INET6 : DEFAULT_FAMILY;

            m_bCircular  = !!::GetPrivateProfileInt(_T("server"), _T("circular"), 0, path);
            m_MaxConnect = ::GetPrivateProfileInt(_T("server"), _T("maxconnect"), m_MaxConnect, path);

            CString buf;

            if (GetConfigString(buf, path, _T("ipaddress"))) { m_addr = buf; }

            if (GetConfigString(buf, path, _T("port"))) { m_port = buf; }

            if (GetConfigString(buf, path, _T("protocol")))
            {
                if (buf.CompareNoCase(_T("TCP")) == 0)
                {
                    m_socktype = SOCK_STREAM;
                }
                else if (buf.CompareNoCase(_T("UDP")) == 0)
                {
                    m_socktype = SOCK_DGRAM;
                }
            }

            // get storage name and interval
            CTask& task = CFactorySingleton<CTask>::Instance();

            UINT interval = ::GetPrivateProfileInt(_T("server"), _T("interval"), 0, path);

            if (interval > 0) { task.SetInterval(interval); }

            if (GetConfigString(buf, path, _T("storage"), STORAGE_NAME))
            {
                path.RemoveFileSpec();
                path.Append(buf);

                task.LoadState(path);
            }
        }

        return ERROR_SUCCESS;
    }
Пример #5
0
void Config::Save()
{
	CXmlWriter XmlWriter;
	XmlWriter.Open("root");

	XmlWriter.AddNewElement("SizeMode");
	XmlWriter.Write("value", Config::SizeMode);

	XmlWriter.AddNewElement("SkinTheme");
	XmlWriter.Write("value", Config::SkinTheme);

	XmlWriter.AddNewElement("ShowFloatBar");
	XmlWriter.Write("value", Config::ShowFloatBar ? 1 : 0);

	XmlWriter.AddNewElement("wVirtualKeyCode");
	XmlWriter.Write("value", Config::wVirtualKeyCode);

	XmlWriter.AddNewElement("wModifiers");
	XmlWriter.Write("value", Config::wModifiers);

	XmlWriter.AddNewElement("CloseMode");
	XmlWriter.Write("value", Config::CloseMode);

	XmlWriter.AddNewElement("StartupMode");
	XmlWriter.Write("value", Config::StartupMode);

	XmlWriter.AddNewElement("Transparent");
	XmlWriter.Write("value", Config::Transparent ? 1 : 0);

	XmlWriter.AddNewElement("TransparentPercent");
	XmlWriter.Write("value", Config::TransparentPercent);


	TCHAR szPath[MAX_PATH + 1] = _T(""); 
	::GetModuleFileName(NULL, szPath, MAX_PATH);
	CPath SaveFile;
	SaveFile = szPath;

	SaveFile.RemoveFileSpec();
	SaveFile.Append(L"config.dat");

	XmlWriter.WriteFile(CStringA(SaveFile));
}
Пример #6
0
UINT_PTR CNavDesktopModule::Main()
{
	if (!CheckInstance())
	{
		return 0;
	}

	if (_InitDownInterface())
	{
		_UpdateSelf();//程序升级
		_UpdateXmlConfig();//更新界面布局xml文件 
	}

	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	{
		TCHAR szPath[MAX_PATH + 1] = _T(""); 
		::GetModuleFileName(NULL, szPath, MAX_PATH);
		CPath ConfigFile;
		ConfigFile = szPath;

		ConfigFile.RemoveFileSpec();
		ConfigFile.Append(L"config.dat");

		CXmlReader XmlReader;
		if (XmlReader.LoadFile(CStringA(ConfigFile)))
		{
			if (XmlReader.Open("root\\SizeMode"))
				XmlReader.Read("value", Config::SizeMode);

			if (XmlReader.Open("root\\SkinTheme"))
				XmlReader.Read("value", Config::SkinTheme);

			if (XmlReader.Open("root\\ShowFloatBar"))
				XmlReader.Read("value", Config::ShowFloatBar);

			if (XmlReader.Open("root\\wVirtualKeyCode"))
				XmlReader.Read("value", (int&)Config::wVirtualKeyCode);

			if (XmlReader.Open("root\\wModifiers"))
				XmlReader.Read("value", (int&)Config::wModifiers);

			if (XmlReader.Open("root\\CloseMode"))
				XmlReader.Read("value", Config::CloseMode);

			if (XmlReader.Open("root\\StartupMode"))
				XmlReader.Read("value", Config::StartupMode);

			if (XmlReader.Open("root\\Transparent"))
				XmlReader.Read("value", Config::Transparent);

			if (XmlReader.Open("root\\TransparentPercent"))
				XmlReader.Read("value", Config::TransparentPercent);
		}
	}

	CMainWnd MainWnd;
	if (MainWnd.Create(NULL) == NULL)
	{
		ATLTRACE(_T("Main dialog creation failed!\n"));
		return 0;
	}

	int nRet = theLoop.Run();
	_Module.RemoveMessageLoop();

	return nRet;
}
Пример #7
0
LONG WINAPI CMiniDump::UnhandledExceptionFilter(_EXCEPTION_POINTERS* lpTopLevelExceptionFilter)
{
    LONG    retval = EXCEPTION_CONTINUE_SEARCH;
    BOOL    bDumpCreated = FALSE;
    HMODULE hDll = nullptr;
    TCHAR   szResult[800];
    szResult[0] = _T('\0');
    CPath   dumpPath;

#if ENABLE_MINIDUMP
    hDll = ::LoadLibrary(_T("dbghelp.dll"));

    if (hDll != nullptr) {
        MINIDUMPWRITEDUMP pMiniDumpWriteDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump");
        if (pMiniDumpWriteDump != nullptr && AfxGetMyApp()->GetAppSavePath(dumpPath)) {
            // Check that the folder actually exists
            if (!FileExists(dumpPath)) {
                VERIFY(CreateDirectory(dumpPath, nullptr));
            }

            CString strDumpName = AfxGetApp()->m_pszExeName;
            strDumpName.Append(_T(".exe.") + VersionInfo::GetVersionString() + _T(".dmp"));
            dumpPath.Append(strDumpName);

            // create the file
            HANDLE hFile = ::CreateFile(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS,
                                        FILE_ATTRIBUTE_NORMAL, nullptr);

            if (hFile != INVALID_HANDLE_VALUE) {
                _MINIDUMP_EXCEPTION_INFORMATION ExInfo;

                ExInfo.ThreadId = ::GetCurrentThreadId();
                ExInfo.ExceptionPointers = lpTopLevelExceptionFilter;
                ExInfo.ClientPointers = FALSE;

                // write the dump
                bDumpCreated = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, nullptr, nullptr);
                if (bDumpCreated) {
                    _stprintf_s(szResult, _countof(szResult), ResStr(IDS_MPC_CRASH), dumpPath);
                    retval = EXCEPTION_EXECUTE_HANDLER;
                } else {
                    _stprintf_s(szResult, _countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), dumpPath, GetLastError());
                }

                ::CloseHandle(hFile);
            } else {
                _stprintf_s(szResult, _countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), dumpPath, GetLastError());
            }
        }
        FreeLibrary(hDll);
    }

    if (szResult[0]) {
        switch (MessageBox(nullptr, szResult, _T("MPC-HC - Mini Dump"), bDumpCreated ? MB_YESNO : MB_OK)) {
            case IDYES:
                ShellExecute(nullptr, _T("open"), BUGS_URL, nullptr, nullptr, SW_SHOWDEFAULT);
                ExploreToFile(dumpPath);
                break;
            case IDNO:
                retval = EXCEPTION_CONTINUE_SEARCH; // rethrow the exception to make easier attaching a debugger
                break;
        }
    }
#else
    if (MessageBox(nullptr, ResStr(IDS_MPC_BUG_REPORT), ResStr(IDS_MPC_BUG_REPORT_TITLE), MB_YESNO) == IDYES) {
        ShellExecute(nullptr, _T("open"), DOWNLOAD_URL, nullptr, nullptr, SW_SHOWDEFAULT);
    }
#endif // DISABLE_MINIDUMP

    return retval;
}