ciderpress/app/NewFolderDialog.cpp
Andy McFadden d8223dbcfd Relocate method comments
This moves method comments from the .cpp file to the .h file,
where users of the methods can find them.  This also makes it
possible for the IDE to show the comments when you mouse-hover over
the method name, though Visual Studio is a bit weak in this regard.

Also, added "override" keywords on overridden methods.  Reasonably
current versions of popular compilers seem to support this.

Also, don't have the return type on a separate line in the .cpp file.
The motivation for the practice -- quickly finding a method definition
with "^name" -- is less useful in C++ than C, and modern IDEs provide
more convenient ways to do the same thing.

Also, do some more conversion from unsigned types to uintXX_t.

This commit is primarily for the "app" directory.
2014-11-21 22:33:39 -08:00

75 lines
2.7 KiB
C++

/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
#include "stdafx.h"
#include "NewFolderDialog.h"
BEGIN_MESSAGE_MAP(NewFolderDialog, CDialog)
ON_WM_HELPINFO()
END_MESSAGE_MAP()
void NewFolderDialog::DoDataExchange(CDataExchange* pDX)
{
/*
* It is very important to keep '\\' out of the folder path, because it allows
* for all sorts of behavior (like "..\foo" or "D:\ack") that the caller
* might not be expecting. For example, if it's displaying a tree, it
* might assume that the folder goes under the currently selected node.
*
* Under WinNT, '/' is regarded as equivalent to '\', so we have to block
* that as well.
*
* Other characters (':') are also dangerous, but so long as we start with
* a valid path, Windows will prevent them from being used where they are
* inappropriate.
*/
if (!pDX->m_bSaveAndValidate)
DDX_Text(pDX, IDC_NEWFOLDER_CURDIR, fCurrentFolder);
DDX_Text(pDX, IDC_NEWFOLDER_NAME, fNewFolder);
/* validate the new folder by creating it */
if (pDX->m_bSaveAndValidate) {
if (fNewFolder.IsEmpty()) {
MessageBox(L"No name entered, not creating new folder.",
L"CiderPress", MB_OK);
// fall out of DoModal with fFolderCreated==false
} else if (fNewFolder.Find('\\') >= 0 ||
fNewFolder.Find('/') >= 0)
{
MessageBox(L"Folder names may not contain '/' or '\\'.",
L"CiderPress", MB_OK);
pDX->Fail();
} else {
fNewFullPath = fCurrentFolder;
if (fNewFullPath.Right(1) != "\\")
fNewFullPath += "\\";
fNewFullPath += fNewFolder;
LOGI("CREATING '%ls'", (LPCWSTR) fNewFullPath);
if (!::CreateDirectory(fNewFullPath, NULL)) {
/* show the sometimes-bizarre Windows error string */
CString msg, errStr, failed;
DWORD dwerr = ::GetLastError();
GetWin32ErrorString(dwerr, &errStr);
msg.Format(L"Unable to create folder '%ls': %ls",
(LPCWSTR) fNewFolder, (LPCWSTR) errStr);
failed.LoadString(IDS_FAILED);
MessageBox(msg, failed, MB_OK | MB_ICONERROR);
pDX->Fail();
} else {
/* success! */
fFolderCreated = true;
}
}
}
}
BOOL NewFolderDialog::OnHelpInfo(HELPINFO* lpHelpInfo)
{
WinHelp((DWORD) lpHelpInfo->iCtrlId, HELP_CONTEXTPOPUP);
return TRUE; // yes, we handled it
}