1 ///////////////////////////////////////////////////////////////////////////////
7 // Copyright (c) 2007 TortoiseSVN
8 // Copyright (c) 2003 Michael Carruth
10 ///////////////////////////////////////////////////////////////////////////////
18 BSTR
CUtility::AllocSysString(string s
)
20 #if defined(_UNICODE) || defined(OLE2ANSI)
21 BSTR bstr
= ::SysAllocStringLen(s
.c_str(), s
.size());
23 int nLen
= MultiByteToWideChar(CP_ACP
, 0, s
.c_str(),
24 s
.size(), NULL
, NULL
);
25 BSTR bstr
= ::SysAllocStringLen(NULL
, nLen
);
27 MultiByteToWideChar(CP_ACP
, 0, s
.c_str(), s
.size(), bstr
, nLen
);
32 FILETIME
CUtility::getLastWriteFileTime(string sFile
)
34 FILETIME ftLocal
= {0};
37 hFind
= FindFirstFile(sFile
.c_str(), &ff32
);
38 if (INVALID_HANDLE_VALUE
!= hFind
)
40 FileTimeToLocalFileTime(&(ff32
.ftLastWriteTime
), &ftLocal
);
46 FILETIME
CUtility::getLastWriteFileTime(WCHAR
* wszFile
)
48 FILETIME ftLocal
= {0};
50 WIN32_FIND_DATAW ff32
;
51 hFind
= FindFirstFileW(wszFile
, &ff32
);
52 if (INVALID_HANDLE_VALUE
!= hFind
)
54 FileTimeToLocalFileTime(&(ff32
.ftLastWriteTime
), &ftLocal
);
60 string
CUtility::getAppName()
62 TCHAR szFileName
[_MAX_PATH
];
63 GetModuleFileName(NULL
, szFileName
, _MAX_FNAME
);
65 string sAppName
; // Extract from last '\' to '.'
67 *_tcsrchr(szFileName
, '.') = '\0';
68 sAppName
= (_tcsrchr(szFileName
, '\\')+1);
74 string
CUtility::getTempFileName()
76 static int counter
= 0;
77 TCHAR szTempDir
[MAX_PATH
- 14] = _T("");
78 TCHAR szTempFile
[MAX_PATH
] = _T("");
80 if (GetTempPath(MAX_PATH
- 14, szTempDir
))
81 GetTempFileName(szTempDir
, getAppName().c_str(), ++counter
, szTempFile
);
87 string
CUtility::getSaveFileName()
89 string sFilter
= _T("Zip Files (*.zip)");
91 OPENFILENAME ofn
= {0}; // common dialog box structure
92 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name
93 // Initialize OPENFILENAME
94 ofn
.lStructSize
= sizeof(OPENFILENAME
);
96 ofn
.lpstrFile
= szFile
;
97 ofn
.nMaxFile
= _countof(szFile
);
98 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
100 ofn
.lpstrFilter
= sFilter
.c_str();
101 ofn
.nFilterIndex
= 1;
102 // Display the Open dialog box.
103 bool bTargetSelected
= !!GetSaveFileName(&ofn
);
105 DeleteFile(ofn
.lpstrFile
); // Just in-case it already exist
106 return ofn
.lpstrFile
;