Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorassarbad <none@none>2008-12-27 05:53:17 +0300
committerassarbad <none@none>2008-12-27 05:53:17 +0300
commit4f22dfcac7a074079e3b02afdaf2976c2085753c (patch)
tree8a38dcac36c7dd5dc55a5aa01671d793541408d8 /windirstat/globalhelpers.cpp
parent22b89178914ec4fe02031b988d051bbcaeed37bb (diff)
- Literally hundreds of cosmetic changes
- First fixes to the multi-select code, especially to allow WDS to run after build ;)
Diffstat (limited to 'windirstat/globalhelpers.cpp')
-rw-r--r--windirstat/globalhelpers.cpp763
1 files changed, 381 insertions, 382 deletions
diff --git a/windirstat/globalhelpers.cpp b/windirstat/globalhelpers.cpp
index 005d4bc..8db9004 100644
--- a/windirstat/globalhelpers.cpp
+++ b/windirstat/globalhelpers.cpp
@@ -19,7 +19,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Author(s): - bseifert -> http://windirstat.info/contact/bernhard/
-// - assarbad -> oliver@windirstat.info
+// - assarbad -> http://windirstat.info/contact/oliver/
//
// $Id$
@@ -33,274 +33,274 @@
namespace
{
- CString FormatLongLongNormal(ULONGLONG n)
- {
- // Returns formatted number like "123.456.789".
-
- ASSERT(n >= 0);
-
- CString all;
-
- do
- {
- int rest = (int)(n % 1000);
- n/= 1000;
-
- CString s;
- if(n > 0)
- {
- s.Format(TEXT("%s%03d"), GetLocaleThousandSeparator(), rest);
- }
- else
- {
- s.Format(TEXT("%d"), rest);
- }
-
- all = s + all;
- } while(n > 0);
-
- return all;
- }
-
- void CacheString(CString& s, UINT resId, LPCTSTR defaultVal)
- {
- ASSERT(_tcslen(defaultVal) > 0);
-
- if(s.IsEmpty())
- {
- s = LoadString(resId);
-
- if(s.IsEmpty())
- {
- s = defaultVal;
- }
- }
- }
+ CString FormatLongLongNormal(ULONGLONG n)
+ {
+ // Returns formatted number like "123.456.789".
+
+ ASSERT(n >= 0);
+
+ CString all;
+
+ do
+ {
+ int rest = (int)(n % 1000);
+ n/= 1000;
+
+ CString s;
+ if(n > 0)
+ {
+ s.Format(_T("%s%03d"), GetLocaleThousandSeparator(), rest);
+ }
+ else
+ {
+ s.Format(_T("%d"), rest);
+ }
+
+ all = s + all;
+ } while(n > 0);
+
+ return all;
+ }
+
+ void CacheString(CString& s, UINT resId, LPCTSTR defaultVal)
+ {
+ ASSERT(_tcslen(defaultVal) > 0);
+
+ if(s.IsEmpty())
+ {
+ s = LoadString(resId);
+
+ if(s.IsEmpty())
+ {
+ s = defaultVal;
+ }
+ }
+ }
}
CString GetLocaleString(LCTYPE lctype, LANGID langid)
{
- LCID lcid = MAKELCID(langid, SORT_DEFAULT);
+ LCID lcid = MAKELCID(langid, SORT_DEFAULT);
- int len = GetLocaleInfo(lcid, lctype, NULL, 0);
- CString s;
+ int len = GetLocaleInfo(lcid, lctype, NULL, 0);
+ CString s;
- GetLocaleInfo(lcid, lctype, s.GetBuffer(len), len);
- s.ReleaseBuffer();
+ GetLocaleInfo(lcid, lctype, s.GetBuffer(len), len);
+ s.ReleaseBuffer();
- return s;
+ return s;
}
CString GetLocaleLanguage(LANGID langid)
{
- CString s = GetLocaleString(LOCALE_SNATIVELANGNAME, langid);
+ CString s = GetLocaleString(LOCALE_SNATIVELANGNAME, langid);
- // In the French case, the system returns "francais",
- // but we want "Francais".
+ // In the French case, the system returns "francais",
+ // but we want "Francais".
- if(s.GetLength() > 0)
- {
- s.SetAt(0, (TCHAR)_totupper(s[0]));
- }
+ if(s.GetLength() > 0)
+ {
+ s.SetAt(0, (TCHAR)_totupper(s[0]));
+ }
- return s + TEXT(" - ") + GetLocaleString(LOCALE_SNATIVECTRYNAME, langid);
+ return s + _T(" - ") + GetLocaleString(LOCALE_SNATIVECTRYNAME, langid);
}
CString GetLocaleThousandSeparator()
{
- return GetLocaleString(LOCALE_STHOUSAND, GetApp()->GetEffectiveLangid());
+ return GetLocaleString(LOCALE_STHOUSAND, GetWDSApp()->GetEffectiveLangid());
}
CString GetLocaleDecimalSeparator()
{
- return GetLocaleString(LOCALE_SDECIMAL, GetApp()->GetEffectiveLangid());
+ return GetLocaleString(LOCALE_SDECIMAL, GetWDSApp()->GetEffectiveLangid());
}
CString FormatBytes(ULONGLONG n)
{
- if(GetOptions()->IsHumanFormat())
- {
- return FormatLongLongHuman(n);
- }
- else
- {
- return FormatLongLongNormal(n);
- }
+ if(GetOptions()->IsHumanFormat())
+ {
+ return FormatLongLongHuman(n);
+ }
+ else
+ {
+ return FormatLongLongNormal(n);
+ }
}
CString FormatLongLongHuman(ULONGLONG n)
{
- // Returns formatted number like "12,4 GB".
- ASSERT(n >= 0);
- const int base = 1024;
- const int half = base / 2;
+ // Returns formatted number like "12,4 GB".
+ ASSERT(n >= 0);
+ const int base = 1024;
+ const int half = base / 2;
- CString s;
+ CString s;
- double B = (int)(n % base);
- n/= base;
+ double B = (int)(n % base);
+ n/= base;
- double KB = (int)(n % base);
- n/= base;
+ double KB = (int)(n % base);
+ n/= base;
- double MB = (int)(n % base);
- n/= base;
+ double MB = (int)(n % base);
+ n/= base;
- double GB = (int)(n % base);
- n/= base;
+ double GB = (int)(n % base);
+ n/= base;
- double TB = (int)(n);
+ double TB = (int)(n);
- if(TB != 0 || GB == base - 1 && MB >= half)
- {
- s.Format(TEXT("%s %s"), FormatDouble(TB + GB/base), GetSpec_TB());
- }
- else if(GB != 0 || MB == base - 1 && KB >= half)
- {
- s.Format(TEXT("%s %s"), FormatDouble(GB + MB/base), GetSpec_GB());
- }
- else if(MB != 0 || KB == base - 1 && B >= half)
- {
- s.Format(TEXT("%s %s"), FormatDouble(MB + KB/base), GetSpec_MB());
- }
- else if(KB != 0)
- {
- s.Format(TEXT("%s %s"), FormatDouble(KB + B/base), GetSpec_KB());
- }
- else if(B != 0)
- {
- s.Format(TEXT("%d %s"), (int)B, GetSpec_Bytes());
- }
- else
- {
- s = TEXT("0");
- }
+ if(TB != 0 || GB == base - 1 && MB >= half)
+ {
+ s.Format(_T("%s %s"), FormatDouble(TB + GB/base), GetSpec_TB());
+ }
+ else if(GB != 0 || MB == base - 1 && KB >= half)
+ {
+ s.Format(_T("%s %s"), FormatDouble(GB + MB/base), GetSpec_GB());
+ }
+ else if(MB != 0 || KB == base - 1 && B >= half)
+ {
+ s.Format(_T("%s %s"), FormatDouble(MB + KB/base), GetSpec_MB());
+ }
+ else if(KB != 0)
+ {
+ s.Format(_T("%s %s"), FormatDouble(KB + B/base), GetSpec_KB());
+ }
+ else if(B != 0)
+ {
+ s.Format(_T("%d %s"), (int)B, GetSpec_Bytes());
+ }
+ else
+ {
+ s = _T("0");
+ }
- return s;
+ return s;
}
CString FormatCount(ULONGLONG n)
{
- return FormatLongLongNormal(n);
+ return FormatLongLongNormal(n);
}
CString FormatDouble(double d) // "98,4" or "98.4"
{
- ASSERT(d >= 0);
+ ASSERT(d >= 0);
- d += 0.05;
+ d += 0.05;
- int i = (int)floor(d);
- int r = (int)(10 * fmod(d, 1));
+ int i = (int)floor(d);
+ int r = (int)(10 * fmod(d, 1));
- CString s;
- s.Format(TEXT("%d%s%d"), i, GetLocaleDecimalSeparator(), r);
+ CString s;
+ s.Format(_T("%d%s%d"), i, GetLocaleDecimalSeparator(), r);
- return s;
+ return s;
}
CString PadWidthBlanks(CString n, int width)
{
- int blankCount = width - n.GetLength();
- if(blankCount > 0)
- {
- int i = 0;
- CString b;
- LPTSTR psz = b.GetBuffer(blankCount + 1);
- for(i = 0; i < blankCount; i++)
- {
- psz[i]= TEXT(' ');
- }
- psz[i]= 0;
- b.ReleaseBuffer();
+ int blankCount = width - n.GetLength();
+ if(blankCount > 0)
+ {
+ int i = 0;
+ CString b;
+ LPTSTR psz = b.GetBuffer(blankCount + 1);
+ for(i = 0; i < blankCount; i++)
+ {
+ psz[i]= _T(' ');
+ }
+ psz[i]= 0;
+ b.ReleaseBuffer();
- n = b + n;
- }
- return n;
+ n = b + n;
+ }
+ return n;
}
CString FormatFileTime(const FILETIME& t)
{
- SYSTEMTIME st;
- if(!FileTimeToSystemTime(&t, &st))
- {
- return MdGetWinErrorText(GetLastError());
- }
+ SYSTEMTIME st;
+ if(!FileTimeToSystemTime(&t, &st))
+ {
+ return MdGetWinErrorText(GetLastError());
+ }
- LCID lcid = MAKELCID(GetApp()->GetEffectiveLangid(), SORT_DEFAULT);
+ LCID lcid = MAKELCID(GetWDSApp()->GetEffectiveLangid(), SORT_DEFAULT);
- CString date;
- VERIFY(0 < GetDateFormat(lcid, DATE_SHORTDATE, &st, NULL, date.GetBuffer(256), 256));
- date.ReleaseBuffer();
+ CString date;
+ VERIFY(0 < GetDateFormat(lcid, DATE_SHORTDATE, &st, NULL, date.GetBuffer(256), 256));
+ date.ReleaseBuffer();
- CString time;
- VERIFY(0 < GetTimeFormat(lcid, 0, &st, NULL, time.GetBuffer(256), 256));
- time.ReleaseBuffer();
+ CString time;
+ VERIFY(0 < GetTimeFormat(lcid, 0, &st, NULL, time.GetBuffer(256), 256));
+ time.ReleaseBuffer();
- return date + TEXT(" ") + time;
+ return date + _T(" ") + time;
}
CString FormatAttributes(DWORD attr)
{
- if(attr == INVALID_FILE_ATTRIBUTES)
- {
- return TEXT("?????");
- }
+ if(attr == INVALID_FILE_ATTRIBUTES)
+ {
+ return _T("??????");
+ }
- CString attributes;
- attributes.Append((attr & FILE_ATTRIBUTE_READONLY ) ? TEXT("R") : strEmpty);
- attributes.Append((attr & FILE_ATTRIBUTE_HIDDEN ) ? TEXT("H") : strEmpty);
- attributes.Append((attr & FILE_ATTRIBUTE_SYSTEM ) ? TEXT("S") : strEmpty);
- attributes.Append((attr & FILE_ATTRIBUTE_ARCHIVE ) ? TEXT("A") : strEmpty);
- attributes.Append((attr & FILE_ATTRIBUTE_COMPRESSED) ? TEXT("C") : strEmpty);
- attributes.Append((attr & FILE_ATTRIBUTE_ENCRYPTED ) ? TEXT("E") : strEmpty);
+ CString attributes;
+ attributes.Append((attr & FILE_ATTRIBUTE_READONLY ) ? _T("R") : strEmpty);
+ attributes.Append((attr & FILE_ATTRIBUTE_HIDDEN ) ? _T("H") : strEmpty);
+ attributes.Append((attr & FILE_ATTRIBUTE_SYSTEM ) ? _T("S") : strEmpty);
+ attributes.Append((attr & FILE_ATTRIBUTE_ARCHIVE ) ? _T("A") : strEmpty);
+ attributes.Append((attr & FILE_ATTRIBUTE_COMPRESSED) ? _T("C") : strEmpty);
+ attributes.Append((attr & FILE_ATTRIBUTE_ENCRYPTED ) ? _T("E") : strEmpty);
- return attributes;
+ return attributes;
}
CString FormatMilliseconds(DWORD ms)
{
- CString ret;
- DWORD sec = (ms + 500) / 1000;
+ CString ret;
+ DWORD sec = (ms + 500) / 1000;
- DWORD s = sec % 60;
- DWORD min = sec / 60;
+ DWORD s = sec % 60;
+ DWORD min = sec / 60;
- DWORD m = min % 60;
+ DWORD m = min % 60;
- DWORD h = min / 60;
+ DWORD h = min / 60;
- if(h > 0)
- {
- ret.Format(TEXT("%u:%02u:%02u"), h, m, s);
- }
- else
- {
- ret.Format(TEXT("%u:%02u"), m, s);
- }
- return ret;
+ if(h > 0)
+ {
+ ret.Format(_T("%u:%02u:%02u"), h, m, s);
+ }
+ else
+ {
+ ret.Format(_T("%u:%02u"), m, s);
+ }
+ return ret;
}
bool GetVolumeName(LPCTSTR rootPath, CString& volumeName)
{
- CString ret;
- DWORD dummy;
+ CString ret;
+ DWORD dummy;
- UINT old = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- bool b = (FALSE != GetVolumeInformation(rootPath, volumeName.GetBuffer(256), 256, &dummy, &dummy, &dummy, NULL, 0));
- volumeName.ReleaseBuffer();
+ UINT old = SetErrorMode(SEM_FAILCRITICALERRORS);
- if(!b)
- {
- TRACE(TEXT("GetVolumeInformation(%s) failed: %u\n"), rootPath, GetLastError());
- }
+ bool b = (FALSE != GetVolumeInformation(rootPath, volumeName.GetBuffer(256), 256, &dummy, &dummy, &dummy, NULL, 0));
+ volumeName.ReleaseBuffer();
- SetErrorMode(old);
-
- return b;
+ if(!b)
+ {
+ TRACE(_T("GetVolumeInformation(%s) failed: %u\n"), rootPath, GetLastError());
+ }
+
+ SetErrorMode(old);
+
+ return b;
}
// Given a root path like "C:\", this function
@@ -308,25 +308,25 @@ bool GetVolumeName(LPCTSTR rootPath, CString& volumeName)
// like "BOOT (C:)".
CString FormatVolumeNameOfRootPath(CString rootPath)
{
- CString ret;
- CString volumeName;
- bool b = GetVolumeName(rootPath, volumeName);
- if(b)
- {
- ret = FormatVolumeName(rootPath, volumeName);
- }
- else
- {
- ret = rootPath;
- }
- return ret;
+ CString ret;
+ CString volumeName;
+ bool b = GetVolumeName(rootPath, volumeName);
+ if(b)
+ {
+ ret = FormatVolumeName(rootPath, volumeName);
+ }
+ else
+ {
+ ret = rootPath;
+ }
+ return ret;
}
CString FormatVolumeName(CString rootPath, CString volumeName)
{
- CString ret;
- ret.Format(TEXT("%s (%s)"), volumeName, rootPath.Left(2));
- return ret;
+ CString ret;
+ ret.Format(_T("%s (%s)"), volumeName, rootPath.Left(2));
+ return ret;
}
// The inverse of FormatVolumeNameOfRootPath().
@@ -334,187 +334,187 @@ CString FormatVolumeName(CString rootPath, CString volumeName)
// Or, if name like "C:\", it returns "C:".
CString PathFromVolumeName(CString name)
{
- int i = name.ReverseFind(chrBracketClose);
- if(i == -1)
- {
- ASSERT(name.GetLength() == 3);
- return name.Left(2);
- }
+ int i = name.ReverseFind(chrBracketClose);
+ if(i == -1)
+ {
+ ASSERT(name.GetLength() == 3);
+ return name.Left(2);
+ }
- ASSERT(i != -1);
- int k = name.ReverseFind(chrBracketOpen);
- ASSERT(k != -1);
- ASSERT(k < i);
- CString path = name.Mid(k + 1, i - k - 1);
- ASSERT(path.GetLength() == 2);
- ASSERT(path[1] == chrColon);
+ ASSERT(i != -1);
+ int k = name.ReverseFind(chrBracketOpen);
+ ASSERT(k != -1);
+ ASSERT(k < i);
+ CString path = name.Mid(k + 1, i - k - 1);
+ ASSERT(path.GetLength() == 2);
+ ASSERT(path[1] == chrColon);
- return path;
+ return path;
}
// Retrieve the "fully qualified parse name" of "My Computer"
CString GetParseNameOfMyComputer()
{
- CComPtr<IShellFolder> sf;
- HRESULT hr = SHGetDesktopFolder(&sf);
- MdThrowFailed(hr, TEXT("SHGetDesktopFolder"));
+ CComPtr<IShellFolder> sf;
+ HRESULT hr = SHGetDesktopFolder(&sf);
+ MdThrowFailed(hr, _T("SHGetDesktopFolder"));
- CCoTaskMem<LPITEMIDLIST> pidl;
- hr = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidl);
- MdThrowFailed(hr, TEXT("SHGetSpecialFolderLocation(CSIDL_DRIVES)"));
+ CCoTaskMem<LPITEMIDLIST> pidl;
+ hr = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidl);
+ MdThrowFailed(hr, _T("SHGetSpecialFolderLocation(CSIDL_DRIVES)"));
- STRRET name;
- ZeroMemory(&name, sizeof(name));
- name.uType = STRRET_CSTR;
- hr = sf->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &name);
- MdThrowFailed(hr, TEXT("GetDisplayNameOf(My Computer)"));
+ STRRET name;
+ ZeroMemory(&name, sizeof(name));
+ name.uType = STRRET_CSTR;
+ hr = sf->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &name);
+ MdThrowFailed(hr, _T("GetDisplayNameOf(My Computer)"));
- return MyStrRetToString(pidl, &name);
+ return MyStrRetToString(pidl, &name);
}
void GetPidlOfMyComputer(LPITEMIDLIST *ppidl)
{
- CComPtr<IShellFolder> sf;
- HRESULT hr = SHGetDesktopFolder(&sf);
- MdThrowFailed(hr, TEXT("SHGetDesktopFolder"));
+ CComPtr<IShellFolder> sf;
+ HRESULT hr = SHGetDesktopFolder(&sf);
+ MdThrowFailed(hr, _T("SHGetDesktopFolder"));
- hr = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, ppidl);
- MdThrowFailed(hr, TEXT("SHGetSpecialFolderLocation(CSIDL_DRIVES)"));
+ hr = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, ppidl);
+ MdThrowFailed(hr, _T("SHGetSpecialFolderLocation(CSIDL_DRIVES)"));
}
void ShellExecuteWithAssocDialog(HWND hwnd, LPCTSTR filename)
{
- CWaitCursor wc;
-
- BOOL bExecuted = ShellExecuteNoThrow(hwnd, NULL, filename, NULL, NULL, SW_SHOWNORMAL);
- if((!bExecuted) && (ERROR_NO_ASSOCIATION == GetLastError()))
- {
- // Q192352
- CString sysDir;
- //-- Get the system directory so that we know where Rundll32.exe resides.
- GetSystemDirectory(sysDir.GetBuffer(_MAX_PATH), _MAX_PATH);
- sysDir.ReleaseBuffer();
-
- CString parameters = TEXT("shell32.dll,OpenAs_RunDLL ");
- bExecuted = ShellExecuteNoThrow(hwnd, TEXT("open"), TEXT("RUNDLL32.EXE"), parameters + filename, sysDir, SW_SHOWNORMAL);
- }
-
- if(!bExecuted)
- {
- MdThrowStringExceptionF(TEXT("ShellExecute failed: %1!s!"), MdGetWinErrorText(GetLastError()));
- }
+ CWaitCursor wc;
+
+ BOOL bExecuted = ShellExecuteNoThrow(hwnd, NULL, filename, NULL, NULL, SW_SHOWNORMAL);
+ if((!bExecuted) && (ERROR_NO_ASSOCIATION == GetLastError()))
+ {
+ // Q192352
+ CString sysDir;
+ //-- Get the system directory so that we know where Rundll32.exe resides.
+ GetSystemDirectory(sysDir.GetBuffer(_MAX_PATH), _MAX_PATH);
+ sysDir.ReleaseBuffer();
+
+ CString parameters = _T("shell32.dll,OpenAs_RunDLL ");
+ bExecuted = ShellExecuteNoThrow(hwnd, _T("open"), _T("RUNDLL32.EXE"), parameters + filename, sysDir, SW_SHOWNORMAL);
+ }
+
+ if(!bExecuted)
+ {
+ MdThrowStringExceptionF(_T("ShellExecute failed: %1!s!"), MdGetWinErrorText(GetLastError()));
+ }
}
CString GetFolderNameFromPath(LPCTSTR path)
{
- CString s = path;
- int i = s.ReverseFind(chrBackslash);
- if(i < 0)
- {
- return s;
- }
- return s.Left(i);
+ CString s = path;
+ int i = s.ReverseFind(chrBackslash);
+ if(i < 0)
+ {
+ return s;
+ }
+ return s.Left(i);
}
CString GetCOMSPEC()
{
- CString cmd;
+ CString cmd;
- DWORD dw = GetEnvironmentVariable(TEXT("COMSPEC"), cmd.GetBuffer(_MAX_PATH), _MAX_PATH);
- cmd.ReleaseBuffer();
+ DWORD dw = GetEnvironmentVariable(_T("COMSPEC"), cmd.GetBuffer(_MAX_PATH), _MAX_PATH);
+ cmd.ReleaseBuffer();
- if(dw == 0)
- {
- TRACE(TEXT("COMSPEC not set.\n"));
- cmd = TEXT("cmd.exe");
- }
- return cmd;
+ if(dw == 0)
+ {
+ TRACE(_T("COMSPEC not set.\n"));
+ cmd = _T("cmd.exe");
+ }
+ return cmd;
}
void WaitForHandleWithRepainting(HANDLE h)
-{
- // Code derived from MSDN sample "Waiting in a Message Loop".
-
- while(true)
- {
- // Read all of the messages in this next loop, removing each message as we read it.
- MSG msg;
- while(PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE))
- {
- DispatchMessage(&msg);
- }
-
- // Wait for WM_PAINT message sent or posted to this queue
- // or for one of the passed handles be set to signaled.
- DWORD r = MsgWaitForMultipleObjects(1, &h, FALSE, INFINITE, QS_PAINT);
-
- // The result tells us the type of event we have.
- if(r == WAIT_OBJECT_0 + 1)
- {
- // New messages have arrived.
- // Continue to the top of the always while loop to dispatch them and resume waiting.
- continue;
- }
- else
- {
- // The handle became signaled.
- break;
- }
- }
+{
+ // Code derived from MSDN sample "Waiting in a Message Loop".
+
+ while(true)
+ {
+ // Read all of the messages in this next loop, removing each message as we read it.
+ MSG msg;
+ while(PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE))
+ {
+ DispatchMessage(&msg);
+ }
+
+ // Wait for WM_PAINT message sent or posted to this queue
+ // or for one of the passed handles be set to signaled.
+ DWORD r = MsgWaitForMultipleObjects(1, &h, FALSE, INFINITE, QS_PAINT);
+
+ // The result tells us the type of event we have.
+ if(r == WAIT_OBJECT_0 + 1)
+ {
+ // New messages have arrived.
+ // Continue to the top of the always while loop to dispatch them and resume waiting.
+ continue;
+ }
+ else
+ {
+ // The handle became signaled.
+ break;
+ }
+ }
}
bool FolderExists(LPCTSTR path)
{
- CFileFind finder;
- BOOL b = finder.FindFile(path);
- if(b)
- {
- finder.FindNextFile();
- return (FALSE != finder.IsDirectory());
- }
- else
- {
- // Here we land, if path is an UNC drive. In this case we
- // try another FindFile:
- b = finder.FindFile(CString(path) + TEXT("\\*.*"));
- return (b != false);
- }
+ CFileFind finder;
+ BOOL b = finder.FindFile(path);
+ if(b)
+ {
+ finder.FindNextFile();
+ return (FALSE != finder.IsDirectory());
+ }
+ else
+ {
+ // Here we land, if path is an UNC drive. In this case we
+ // try another FindFile:
+ b = finder.FindFile(CString(path) + _T("\\*.*"));
+ return (b != false);
+ }
}
bool DriveExists(const CString& path)
{
- if(path.GetLength() != 3 || path[1] != chrColon || path[2] != chrBackslash)
- {
- return false;
- }
+ if(path.GetLength() != 3 || path[1] != chrColon || path[2] != chrBackslash)
+ {
+ return false;
+ }
+
+ CString letter = path.Left(1);
+ letter.MakeLower();
+ int d = letter[0] - chrSmallA;
- CString letter = path.Left(1);
- letter.MakeLower();
- int d = letter[0] - chrSmallA;
-
- DWORD mask = 0x1 << d;
+ DWORD mask = 0x1 << d;
- if((mask & GetLogicalDrives()) == 0)
- {
- return false;
- }
+ if((mask & GetLogicalDrives()) == 0)
+ {
+ return false;
+ }
- CString dummy;
- if(!GetVolumeName(path, dummy))
- {
- return false;
- }
+ CString dummy;
+ if(!GetVolumeName(path, dummy))
+ {
+ return false;
+ }
- return true;
+ return true;
}
CString GetUserName()
{
- CString s;
- DWORD size = UNLEN + 1;
- (void)GetUserName(s.GetBuffer(size), &size);
- s.ReleaseBuffer();
- return s;
+ CString s;
+ DWORD size = UNLEN + 1;
+ (void)GetUserName(s.GetBuffer(size), &size);
+ s.ReleaseBuffer();
+ return s;
}
// drive is a drive spec like C: or C:\ or C:\path (path is ignored).
@@ -525,7 +525,7 @@ CString GetUserName()
// Something like
//
// \Device\Harddisk\Volume1 for a local drive
-// \Device\LanmanRedirector\;T:0000000011e98\spock\temp for a network drive
+// \Device\LanmanRedirector\;T:0000000011e98\spock\temp for a network drive
// \??\C:\programme for a SUBSTed local path
// \??\T:\Neuer Ordner for a SUBSTed SUBSTed path
// \??\UNC\spock\temp for a SUBSTed UNC path
@@ -538,39 +538,39 @@ CString GetUserName()
//
// assarbad:
// It cannot be safely determined wether a path is or is not SUBSTed on NT
-// via this API. You would have to lookup the volume mount points because
-// SUBST only works per session by definition whereas volume mount points
-// work accross sessions (after restarts).
+// via this API. You would have to lookup the volume mount points because
+// SUBST only works per session by definition whereas volume mount points
+// work accross sessions (after restarts).
//
CString MyQueryDosDevice(LPCTSTR drive)
{
- CString d = drive;
+ CString d = drive;
- if(d.GetLength() < 2 || d[1] != chrColon)
- {
- return strEmpty;
- }
+ if(d.GetLength() < 2 || d[1] != chrColon)
+ {
+ return strEmpty;
+ }
- d = d.Left(2);
+ d = d.Left(2);
- CQueryDosDeviceApi api;
-
- if(!api.IsSupported())
- {
- return strEmpty;
- }
+ CQueryDosDeviceApi api;
- CString info;
- DWORD dw = api.QueryDosDevice(d, info.GetBuffer(512), 512);
- info.ReleaseBuffer();
+ if(!api.IsSupported())
+ {
+ return strEmpty;
+ }
- if(dw == 0)
- {
- TRACE(TEXT("QueryDosDevice(%s) failed: %s\r\n"), d, MdGetWinErrorText(GetLastError()));
- return strEmpty;
- }
+ CString info;
+ DWORD dw = api.QueryDosDevice(d, info.GetBuffer(512), 512);
+ info.ReleaseBuffer();
- return info;
+ if(dw == 0)
+ {
+ TRACE(_T("QueryDosDevice(%s) failed: %s\r\n"), d, MdGetWinErrorText(GetLastError()));
+ return strEmpty;
+ }
+
+ return info;
}
// drive is a drive spec like C: or C:\ or C:\path (path is ignored).
@@ -580,43 +580,43 @@ CString MyQueryDosDevice(LPCTSTR drive)
//
bool IsSUBSTedDrive(LPCTSTR drive)
{
- CString info = MyQueryDosDevice(drive);
- return (info.GetLength() >= 4 && info.Left(4) == "\\??\\");
+ CString info = MyQueryDosDevice(drive);
+ return (info.GetLength() >= 4 && info.Left(4) == "\\??\\");
}
CString GetSpec_Bytes()
{
- static CString s;
- CacheString(s, IDS_SPEC_BYTES, TEXT("Bytes"));
- return s;
+ static CString s;
+ CacheString(s, IDS_SPEC_BYTES, _T("Bytes"));
+ return s;
}
CString GetSpec_KB()
{
- static CString s;
- CacheString(s, IDS_SPEC_KB, TEXT("KB"));
- return s;
+ static CString s;
+ CacheString(s, IDS_SPEC_KB, _T("kiB"));
+ return s;
}
CString GetSpec_MB()
{
- static CString s;
- CacheString(s, IDS_SPEC_MB, TEXT("MB"));
- return s;
+ static CString s;
+ CacheString(s, IDS_SPEC_MB, _T("MiB"));
+ return s;
}
CString GetSpec_GB()
{
- static CString s;
- CacheString(s, IDS_SPEC_GB, TEXT("GB"));
- return s;
+ static CString s;
+ CacheString(s, IDS_SPEC_GB, _T("GiB"));
+ return s;
}
CString GetSpec_TB()
{
- static CString s;
- CacheString(s, IDS_SPEC_TB, TEXT("TB"));
- return s;
+ static CString s;
+ CacheString(s, IDS_SPEC_TB, _T("TiB"));
+ return s;
}
/*
@@ -624,17 +624,16 @@ CString GetSpec_TB()
// Returns a valid pidl, or throws an exception.
LPCITEMIDLIST SHGetPIDLFromPath(CString path)
{
- USES_CONVERSION;
+ USES_CONVERSION;
- CComPtr<IShellFolder> pshf;
- HRESULT hr = SHGetDesktopFolder(&pshf);
- MdThrowFailed(hr, TEXT("SHGetDesktopFolder"));
+ CComPtr<IShellFolder> pshf;
+ HRESULT hr = SHGetDesktopFolder(&pshf);
+ MdThrowFailed(hr, _T("SHGetDesktopFolder"));
- LPITEMIDLIST pidl;
- hr = pshf->ParseDisplayName(NULL, NULL, const_cast<LPOLESTR>(T2CW(path)), NULL, &pidl, NULL);
- MdThrowFailed(hr, TEXT("ParseDisplayName"));
+ LPITEMIDLIST pidl;
+ hr = pshf->ParseDisplayName(NULL, NULL, const_cast<LPOLESTR>(T2CW(path)), NULL, &pidl, NULL);
+ MdThrowFailed(hr, _T("ParseDisplayName"));
- return pidl;
+ return pidl;
}
*/
-