*/\r
DWORD NTAPI VersionOf7z()\r
{\r
- String path = paths::ConcatPath(env_GetProgPath(), _T("Merge7z\\7z.dll"));\r
+ String path = paths::ConcatPath(env::GetProgPath(), _T("Merge7z\\7z.dll"));\r
unsigned versionMS = 0;\r
unsigned versionLS = 0;\r
CVersionInfo(path.c_str()).GetFixedFileVersion(versionMS, versionLS);\r
if (piHandler = ArchiveGuessFormat(res.files[0]))\r
{\r
res.pTempPathContext = new CTempPathContext;\r
- path = env_GetTempChildPath();\r
+ path = env::GetTempChildPath();\r
for (int index = 0; index < res.files.GetSize(); index++)\r
res.pTempPathContext->m_strDisplayRoot[index] = res.files[index];\r
if (res.files.GetSize() == 2 && res.files[0] == res.files[1])\r
for (int index = 0; index < res.files.GetSize(); index++)\r
res.pTempPathContext->m_strDisplayRoot[index] = res.files[index];\r
}\r
- path = env_GetTempChildPath();\r
+ path = env::GetTempChildPath();\r
do\r
{\r
if (FAILED(piHandler->DeCompressArchive(hWnd, res.files[1].c_str(), path.c_str())))\r
for (int index = 0; index < res.files.GetSize(); index++)\r
res.pTempPathContext->m_strDisplayRoot[index] = res.files[index];\r
}\r
- path = env_GetTempChildPath();\r
+ path = env::GetTempChildPath();\r
do\r
{\r
if (FAILED(piHandler->DeCompressArchive(hWnd, res.files[2].c_str(), path.c_str())))\r
String CLanguageSelect::GetFileName(LANGID wLangId) const
{
String filename;
- String path = paths::ConcatPath(env_GetProgPath(), szRelativePath);
+ String path = paths::ConcatPath(env::GetProgPath(), szRelativePath);
String pattern = paths::ConcatPath(path, _T("*.po"));
WIN32_FIND_DATA ff;
HANDLE h = INVALID_HANDLE_VALUE;
std::vector<std::pair<LANGID, String> > CLanguageSelect::GetAvailableLanguages() const
{
std::vector<std::pair<LANGID, String> > list;
- String path = paths::ConcatPath(env_GetProgPath(), szRelativePath);
+ String path = paths::ConcatPath(env::GetProgPath(), szRelativePath);
String pattern = paths::ConcatPath(path, _T("*.po"));
WIN32_FIND_DATA ff;
HANDLE h = INVALID_HANDLE_VALUE;
{
if (m_tempFilenameDst.empty())
{
- m_tempFilenameDst = env_GetTempFileName(env_GetTempPath(), _T ("_WM"));
+ m_tempFilenameDst = env::GetTemporaryFileName(env::GetTemporaryPath(), _T ("_WM"));
}
return m_tempFilenameDst.c_str();
}
CVersionInfo version;
String text;
- String sFileName = paths::ConcatPath(env_GetMyDocuments(), WinMergeDocumentsFolder);
+ String sFileName = paths::ConcatPath(env::GetMyDocuments(), WinMergeDocumentsFolder);
paths::CreateIfNeeded(sFileName);
m_sFileName = paths::ConcatPath(sFileName, _T("WinMerge.txt"));
}
else
{
- sIntermediateFilename = env_GetTempFileName(m_strTempPath,
+ sIntermediateFilename = env::GetTemporaryFileName(m_strTempPath,
_T("MRG_"), NULL);
if (sIntermediateFilename.empty())
return SAVE_FAILED; //Nothing to do if even tempfile name fails
// what differences diff-engine sees!
#ifdef _DEBUG
// throw the diff into a temp file
- String sTempPath = env_GetTempPath(); // get path to Temp folder
+ String sTempPath = env::GetTemporaryPath(); // get path to Temp folder
String path = paths::ConcatPath(sTempPath, _T("Diff.txt"));
outfile = _tfopen(path.c_str(), _T("w+"));
}
else if (paths::IsDecendant(files[i], szTempPath) || paths::IsDecendant(files[i], szTempPathShort))
{
- String tmpdir = env_GetTempChildPath();
+ String tmpdir = env::GetTempChildPath();
CopyFileOrFolder(files[i], tmpdir);
files[i] = paths::ConcatPath(tmpdir, paths::FindFileName(files[i]));
}
if (SUCCEEDED(hr = pFileOperation.CreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL)))
{
if (tmpdir.empty())
- tmpdir = env_GetTempChildPath();
+ tmpdir = env::GetTempChildPath();
pFileOperation->SetOperationFlags(0);
PIDLIST_ABSOLUTE pidlDest;
if (SUCCEEDED(hr = SHParseDisplayName(ucr::toUTF16(tmpdir).c_str(), NULL, &pidlDest, 0, NULL)))
HRESULT GetFileItemsFromIDataObject_FileDescriptor(IDataObject *pDataObj, std::vector<String>& root_files)
{
- String tmpdir = env_GetTempChildPath();
+ String tmpdir = env::GetTempChildPath();
FORMATETC fmtetc_filedescriptor = { static_cast<WORD>(RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR)), NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM medium = { 0 };
HRESULT hr;
using Poco::Path;
using Poco::Process;
+namespace env
+{
+
/**
* @brief Temp path.
- * Static string used by env_GetTempPath() for storing temp path.
+ * Static string used by GetTemporaryPath() for storing temp path.
*/
static String strTempPath;
static String strProgPath;
-void env_SetTempPath(const String& path)
+void SetTemporaryPath(const String& path)
{
strTempPath = paths::AddTrailingSlash(paths::GetLongPath(path));
paths::CreateIfNeeded(strTempPath);
* @note Temp path is cached after first call.
* @todo Should we return NULL for error case?
*/
-String env_GetTempPath()
+String GetTemporaryPath()
{
if (strTempPath.empty())
{
- strTempPath = env_GetSystemTempPath();
+ strTempPath = GetSystemTempPath();
if (strTempPath.empty())
return strTempPath;
* @param [out] pnerr Error code if error happened.
* @return Full path for temporary file or empty string if error happened.
*/
-String env_GetTempFileName(const String& lpPathName, const String& lpPrefixString, int * pnerr)
+String GetTemporaryFileName(const String& lpPathName, const String& lpPrefixString, int * pnerr)
{
TCHAR buffer[MAX_PATH] = {0};
if (lpPathName.length() > MAX_PATH-14)
return _T(""); // failure
- int rtn = GetTempFileName(lpPathName.c_str(), lpPrefixString.c_str(), 0, buffer);
+ int rtn = ::GetTempFileName(lpPathName.c_str(), lpPrefixString.c_str(), 0, buffer);
if (!rtn)
{
int err = GetLastError();
return buffer;
}
-String env_GetTempChildPath()
+String GetTempChildPath()
{
String path;
do
{
- path = paths::ConcatPath(env_GetTempPath(), string_format(_T("%08x"), rand()));
+ path = paths::ConcatPath(GetTemporaryPath(), string_format(_T("%08x"), rand()));
} while (paths::IsDirectory(path) || !paths::CreateIfNeeded(path));
return path;
}
-void env_SetProgPath(const String& path)
+void SetProgPath(const String& path)
{
strProgPath = paths::AddTrailingSlash(path);
}
-String env_GetProgPath()
+String GetProgPath()
{
if (strProgPath.empty())
{
* @brief Get Windows directory.
* @return Windows directory.
*/
-String env_GetWindowsDirectory()
+String GetWindowsDirectory()
{
TCHAR path[MAX_PATH];
path[0] = _T('\0');
- GetWindowsDirectory(path, MAX_PATH);
+ ::GetWindowsDirectory(path, MAX_PATH);
return path;
}
* This function returns full path to User's My Documents -folder.
* @return Full path to My Documents -folder.
*/
-String env_GetMyDocuments()
+String GetMyDocuments()
{
TCHAR path[MAX_PATH];
path[0] = _T('\0');
* @param [in] name Additional name used as part of the string.
* @return Unique string for the instance.
*/
-String env_GetPerInstanceString(const String& name)
+String GetPerInstanceString(const String& name)
{
std::basic_stringstream<TCHAR> stream;
stream << name << Process::id();
* @brief Get system temporary directory.
* @return System temporary director.
*/
-String env_GetSystemTempPath()
+String GetSystemTempPath()
{
try
{
/**
* @brief Load registry keys from .reg file if existing .reg file
*/
-bool env_LoadRegistryFromFile(const String& sRegFilePath)
+bool LoadRegistryFromFile(const String& sRegFilePath)
{
if (paths::DoesPathExist(sRegFilePath) != paths::IS_EXISTING_FILE)
return false;
/**
* @brief Save registry keys to .reg file if existing .reg file
*/
-bool env_SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir)
+bool SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir)
{
if (paths::DoesPathExist(sRegFilePath) != paths::IS_EXISTING_FILE)
return false;
DeleteFile(sRegFilePath.c_str());
return launchProgram(_T("reg.exe export HKCU\\") + sRegDir + _T(" \"") + sRegFilePath + _T("\""), SW_HIDE);
}
+
+}
#include "UnicodeString.h"
-void env_SetTempPath(const String& path);
-String env_GetTempPath();
-String env_GetTempFileName(const String& lpPathName, const String& lpPrefixString,
+namespace env
+{
+
+void SetTemporaryPath(const String& path);
+String GetTemporaryPath();
+String GetTemporaryFileName(const String& lpPathName, const String& lpPrefixString,
int * pnerr = NULL);
-String env_GetTempChildPath();
-void env_SetProgPath(const String& path);
-String env_GetProgPath();
+String GetTempChildPath();
+void SetProgPath(const String& path);
+String GetProgPath();
+
+String GetWindowsDirectory();
+String GetMyDocuments();
+String GetSystemTempPath();
-String env_GetWindowsDirectory();
-String env_GetMyDocuments();
-String env_GetSystemTempPath();
+String GetPerInstanceString(const String& name);
-String env_GetPerInstanceString(const String& name);
+bool LoadRegistryFromFile(const String& sRegFilePath);
+bool SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir);
-bool env_LoadRegistryFromFile(const String& sRegFilePath);
-bool env_SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir);
+}
m_fileFilterMgr->DeleteAllFilters();
// Program application directory
- m_sGlobalFilterPath = paths::ConcatPath(env_GetProgPath(), _T("Filters"));
+ m_sGlobalFilterPath = paths::ConcatPath(env::GetProgPath(), _T("Filters"));
paths::normalize(m_sGlobalFilterPath);
String pattern(_T("*"));
pattern += FileFilterExt;
bool FileTransform_AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite)
{
- String tempDir = env_GetTempPath();
+ String tempDir = env::GetTemporaryPath();
if (tempDir.empty())
return false;
- String tempFilepath = env_GetTempFileName(tempDir, _T("_W3"));
+ String tempFilepath = env::GetTemporaryFileName(tempDir, _T("_W3"));
if (tempFilepath.empty())
return false;
// TODO : is it better with the BOM or without (just change the last argument)
int SectionNo = 0;\r
if (m_IniFileName.empty())\r
{\r
- m_IniFileName = paths::ConcatPath(env_GetProgPath(), _T("IgnoreSectionMarkers.ini"));\r
+ m_IniFileName = paths::ConcatPath(env::GetProgPath(), _T("IgnoreSectionMarkers.ini"));\r
}\r
\r
try\r
if (!theApp.CreateBackup(FALSE, path))
return S_OK;
// Write data to an intermediate file
- String tempPath = env_GetTempPath();
- String sIntermediateFilename = env_GetTempFileName(tempPath, _T("MRG_"), 0);
+ String tempPath = env::GetTemporaryPath();
+ String sIntermediateFilename = env::GetTemporaryFileName(tempPath, _T("MRG_"), 0);
if (sIntermediateFilename.empty())
return E_FAIL; //Nothing to do if even tempfile name fails
HANDLE h = CreateFile(sIntermediateFilename.c_str(), GENERIC_WRITE, FILE_SHARE_READ,
*/
void CMainFrame::OnHelpGnulicense()
{
- const String spath = paths::ConcatPath(env_GetProgPath(), LicenseFile);
+ const String spath = paths::ConcatPath(env::GetProgPath(), LicenseFile);
theApp.OpenFileOrUrl(spath.c_str(), LicenceUrl);
}
pOldFilter->Revoke();
// Load registry keys from WinMerge.reg if existing WinMerge.reg
- env_LoadRegistryFromFile(paths::ConcatPath(env_GetProgPath(), _T("WinMerge.reg")));
+ env::LoadRegistryFromFile(paths::ConcatPath(env::GetProgPath(), _T("WinMerge.reg")));
Options::Init(m_pOptions.get()); // Implementation in OptionsInit.cpp
// Failed to create a folder for filters, fallback to
// "My Documents"-folder. It is not worth the trouble to
// bother user about this or user more clever solutions.
- GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, env_GetMyDocuments());
+ GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, env::GetMyDocuments());
}
}
static void OpenContributersFile(int&)
{
- theApp.OpenFileToExternalEditor(paths::ConcatPath(env_GetProgPath(), ContributorsPath));
+ theApp.OpenFileToExternalEditor(paths::ConcatPath(env::GetProgPath(), ContributorsPath));
}
// App command to run the dialog
charsets_cleanup();
// Save registry keys if existing WinMerge.reg
- env_SaveRegistryToFile(paths::ConcatPath(env_GetProgPath(), _T("WinMerge.reg")), RegDir);
+ env::SaveRegistryToFile(paths::ConcatPath(env::GetProgPath(), _T("WinMerge.reg")), RegDir);
// Remove tempfolder
- const String temp = env_GetTempPath();
+ const String temp = env::GetTemporaryPath();
ClearTempfolder(temp);
delete m_mainThreadScripts;
CWinApp::ExitInstance();
*/
void CMergeApp::ShowHelp(LPCTSTR helpLocation /*= NULL*/)
{
- String sPath = env_GetProgPath();
+ String sPath = env::GetProgPath();
LANGID LangId = GetLangId();
if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
sPath = paths::ConcatPath(sPath, DocsPath_ja);
void CMergeApp::SetupTempPath()
{
- String instTemp = env_GetPerInstanceString(TempFolderPrefix);
+ String instTemp = env::GetPerInstanceString(TempFolderPrefix);
if (GetOptionsMgr()->GetBool(OPT_USE_SYSTEM_TEMP_PATH))
- env_SetTempPath(paths::ConcatPath(env_GetSystemTempPath(), instTemp));
+ env::SetTemporaryPath(paths::ConcatPath(env::GetSystemTempPath(), instTemp));
else
- env_SetTempPath(paths::ConcatPath(GetOptionsMgr()->GetString(OPT_CUSTOM_TEMP_PATH), instTemp));
+ env::SetTemporaryPath(paths::ConcatPath(GetOptionsMgr()->GetString(OPT_CUSTOM_TEMP_PATH), instTemp));
}
/**
CheckFileChanged();
- String tempPath = env_GetTempPath();
+ String tempPath = env::GetTemporaryPath();
// Set up DiffWrapper
m_diffWrapper.GetOptions(&diffOptions);
pOptions->InitOption(OPT_TAB_SIZE, (int)4);
pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted
- pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env_GetWindowsDirectory(), _T("NOTEPAD.EXE")));
+ pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE")));
pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
pOptions->InitOption(OPT_SINGLE_INSTANCE, false);
pOptions->InitOption(OPT_MERGE_MODE, false);
pOptions->InitOption(OPT_LINEFILTER_ENABLED, false);
pOptions->InitOption(OPT_FILEFILTER_CURRENT, _T("*.*"));
// CMainFrame initializes this when it is empty.
- pOptions->InitOption(OPT_FILTER_USERPATH, paths::ConcatPath(env_GetMyDocuments(), DefaultRelativeFilterPath));
+ pOptions->InitOption(OPT_FILTER_USERPATH, paths::ConcatPath(env::GetMyDocuments(), DefaultRelativeFilterPath));
pOptions->InitOption(OPT_FILEFILTER_SHARED, false);
pOptions->InitOption(OPT_CP_DEFAULT_MODE, (int)0);
if (m_fileResult.length() == 0)
{
TCHAR szTempFile[MAX_PATH];
- GetTempFileName(env_GetTempPath().c_str(), _T("pat"), 0, szTempFile);
+ ::GetTempFileName(env::GetTemporaryPath().c_str(), _T("pat"), 0, szTempFile);
m_fileResult = szTempFile;
m_ctlResult.SetWindowText(m_fileResult.c_str());
DeleteFile(m_fileResult.c_str());
FastMutex::ScopedLock lock(scriptletsSem);
if (!scriptletsLoaded)
{
- String path = paths::ConcatPath(env_GetProgPath(), _T("MergePlugins"));
+ String path = paths::ConcatPath(env::GetProgPath(), _T("MergePlugins"));
if (IsWindowsScriptThere())
GetScriptletsAt(path, _T(".sct"), theScriptletList ); // VBS/JVS scriptlet
GetSystemDirectory(szSystem32, sizeof(szSystem32) / sizeof(szSystem32[0]));
GetSystemWow64Directory(szSysWow64, sizeof(szSysWow64) / sizeof(szSysWow64[0]));
- String progpath = env_GetProgPath();
+ String progpath = env::GetProgPath();
String regsvr32 = paths::ConcatPath(szSystem32, _T("regsvr32.exe"));
String args;
SHELLEXECUTEINFO sei = { sizeof(sei) };
*/
String TempFile::Create(const String& prefix, const String& ext)
{
- String temp = env_GetTempPath();
+ String temp = env::GetTemporaryPath();
if (temp.empty())
{
return _T("");
if (pref.empty())
pref = _T("wmtmp");
- temp = env_GetTempFileName(temp, pref, NULL);
+ temp = env::GetTemporaryFileName(temp, pref, NULL);
if (!temp.empty())
{
if (!ext.empty())
*/
String TempFile::CreateFromFile(const String& filepath, const String& prefix)
{
- String temp = env_GetTempPath();
+ String temp = env::GetTemporaryPath();
if (temp.empty())
{
return _T("");
if (pref.empty())
pref = _T("wmtmp");
- temp = env_GetTempFileName(temp, pref, NULL);
+ temp = env::GetTemporaryFileName(temp, pref, NULL);
if (!temp.empty())
{
// Scratchpads don't have a file to copy.
String tempfolderPID;
String filepattern(TempFolderPrefix);
filepattern += _T("*.*");
- String pattern = paths::GetParentPath(env_GetTempPath());
+ String pattern = paths::GetParentPath(env::GetTemporaryPath());
pattern = paths::ConcatPath(pattern, filepattern);
WIN32_FIND_DATA ff;
HANDLE h;
{
const UINT nBufferSize = 1024;
- String tempFile = env_GetTempFileName(env_GetTempPath(), _T("_LT"));
+ String tempFile = env::GetTemporaryFileName(env::GetTemporaryPath(), _T("_LT"));
if (tempFile.empty())
{
LogErrorString(_T("CMainFrame::ReLinkVCProj() - couldn't get tempfile"));
TEST_F(EnvironmentTest, LoadRegistryFromFile)
{
- EXPECT_EQ(false, env_LoadRegistryFromFile(_T("nonexistfile.reg")));
+ EXPECT_EQ(false, env::LoadRegistryFromFile(_T("nonexistfile.reg")));
system(
"reg add HKCU\\Software\\Thingamahoochie\\test /v Path /t REG_EXPAND_SZ /d \"abc\" & "
"reg export HKCU\\Software\\Thingamahoochie\\test test.reg & "
"reg delete HKCU\\Software\\Thingamahoochie\\test /f");
- EXPECT_EQ(true, env_LoadRegistryFromFile(_T("test.reg")));
+ EXPECT_EQ(true, env::LoadRegistryFromFile(_T("test.reg")));
EXPECT_EQ(0, system("reg query HKCU\\Software\\Thingamahoochie\\test /v Path | findstr abc"));
system("reg delete HKCU\\Software\\Thingamahoochie\\test /f");
remove("test.reg");
TEST_F(EnvironmentTest, SaveRegistry)
{
- EXPECT_EQ(false, env_SaveRegistryToFile(_T("nonexistfile.reg"), _T("Software\\Thingamahoochie\\tes")));
+ EXPECT_EQ(false, env::SaveRegistryToFile(_T("nonexistfile.reg"), _T("Software\\Thingamahoochie\\tes")));
system("reg add HKCU\\Software\\Thingamahoochie\\test /v Path /t REG_EXPAND_SZ /d \"abc\"");
system("echo. > test2.reg");
- EXPECT_EQ(true, env_SaveRegistryToFile(_T("test2.reg"), _T("Software\\Thingamahoochie\\test")));
+ EXPECT_EQ(true, env::SaveRegistryToFile(_T("test2.reg"), _T("Software\\Thingamahoochie\\test")));
EXPECT_EQ(0, system("type test2.reg|findstr Path"));
system("reg delete HKCU\\Software\\Thingamahoochie\\test /f");
remove("test2.reg");
// before each test).
TCHAR temp[MAX_PATH] = {0};
GetModuleFileName(NULL, temp, MAX_PATH);
- env_SetProgPath(paths::GetPathOnly(temp) + _T("/../FileFilter"));
+ env::SetProgPath(paths::GetPathOnly(temp) + _T("/../FileFilter"));
m_fileFilterHelper.LoadAllFileFilters();
}
TEST_F(PluginsTest, Unpack)
{
- String oldModulePath = env_GetProgPath();
- env_SetProgPath(_T("c:/program files (x86)/winmerge"));
+ String oldModulePath = env::GetProgPath();
+ env::SetProgPath(_T("c:/program files (x86)/winmerge"));
CAssureScriptsForThread asft;
PackingInfo *iu = NULL;
PrediffingInfo *ip = NULL;