Menu

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

Download this file

75 lines (63 with data), 1.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
#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);
}
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.