Menu

[r73]: / trunk / src / AppUtils.cpp  Maximize  Restore  History

Download this file

117 lines (99 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "StdAfx.h"
#include "AppUtils.h"
#include <shlwapi.h>
#include <shlobj.h>
#pragma comment(lib, "shlwapi.lib")
CAppUtils::CAppUtils(void)
{
}
CAppUtils::~CAppUtils(void)
{
}
wstring CAppUtils::GetAppDataDir()
{
WCHAR path[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
PathAppend(path, _T("CommitMonitor"));
if (!PathFileExists(path))
CreateDirectory(path, NULL);
return wstring(path);
}
wstring CAppUtils::ConvertDate(apr_time_t time)
{
apr_time_exp_t exploded_time = {0};
SYSTEMTIME systime;
TCHAR timebuf[1024];
TCHAR datebuf[1024];
LCID locale = MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT);
apr_time_exp_lt (&exploded_time, time);
systime.wDay = (WORD)exploded_time.tm_mday;
systime.wDayOfWeek = (WORD)exploded_time.tm_wday;
systime.wHour = (WORD)exploded_time.tm_hour;
systime.wMilliseconds = (WORD)(exploded_time.tm_usec/1000);
systime.wMinute = (WORD)exploded_time.tm_min;
systime.wMonth = (WORD)exploded_time.tm_mon+1;
systime.wSecond = (WORD)exploded_time.tm_sec;
systime.wYear = (WORD)exploded_time.tm_year+1900;
GetDateFormat(locale, DATE_SHORTDATE, &systime, NULL, datebuf, 1024);
GetTimeFormat(locale, 0, &systime, NULL, timebuf, 1024);
wstring sRet = datebuf;
sRet += _T(" ");
sRet += timebuf;
return sRet;
}
void CAppUtils::SearchReplace(wstring& str, const wstring& toreplace, const wstring& replacewith)
{
wstring result;
wstring::size_type pos = 0;
while(true)
{
wstring::size_type next = str.find(toreplace, pos);
result.append(str, pos, next-pos);
if( next != std::string::npos )
{
result.append(replacewith);
pos = next + toreplace.size();
}
else
{
break; // exit loop
}
}
str.swap(result);
}
bool CAppUtils::LaunchApplication(const wstring& sCommandLine, bool bWaitForStartup)
{
STARTUPINFO startup;
PROCESS_INFORMATION process;
memset(&startup, 0, sizeof(startup));
startup.cb = sizeof(startup);
memset(&process, 0, sizeof(process));
TCHAR * cmdbuf = new TCHAR[sCommandLine.length()+1];
_tcscpy_s(cmdbuf, sCommandLine.length()+1, sCommandLine.c_str());
if (CreateProcess(NULL, cmdbuf, NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
{
delete [] cmdbuf;
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
::MessageBox(NULL, (LPCWSTR)lpMsgBuf, _T("CommitMonitor"), MB_ICONERROR);
LocalFree(lpMsgBuf);
return false;
}
delete [] cmdbuf;
if (bWaitForStartup)
{
WaitForInputIdle(process.hProcess, 10000);
}
CloseHandle(process.hThread);
CloseHandle(process.hProcess);
return true;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.