2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
#include "StdAfx.h"
|
2014-12-05 01:05:48 +00:00
|
|
|
#include "DiskFSTree.h"
|
2007-03-27 17:47:10 +00:00
|
|
|
#include "ChooseAddTargetDialog.h"
|
Volume name and font fixes
More volume name MOR conversions. I think I got them all.
This also switches the "archive info", "add files", and "extract
files" dialogs to use the System Font. We were using "MS Sans
Serif" before, which looks a bit ratty on Windows 7 because it
doesn't take advantage of ClearType. (Apparently the ClearType
version is "Microsoft Sans Serif", though when you set the "use
system font" boolean to true it changes the font name to "MS Shell
Dlg".) The old font also seems to be missing certain glyphs, e.g.
my HFS volume name had 'TM' in it, but that just showed up as a box
(which is why, in case you were wondering, these changes ended up
together).
The new font seems to work equally well on WinXP, so I may enable
it for all dialogs in a follow-up change. As far as I can tell it
has the same font metrics -- I haven't seen anything weird looking
in the dialogs I've updated so far.
Also, bumped the version to 4.0.0-b3.
2015-01-15 19:25:26 +00:00
|
|
|
#include "../reformat/Charset.h"
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
using namespace DiskImgLib;
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
bool DiskFSTree::BuildTree(DiskFS* pDiskFS, CTreeCtrl* pTree)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pDiskFS != NULL);
|
|
|
|
ASSERT(pTree != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
pTree->SetImageList(&fTreeImageList, TVSIL_NORMAL);
|
|
|
|
return AddDiskFS(pTree, TVI_ROOT, pDiskFS, 1);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
bool DiskFSTree::AddDiskFS(CTreeCtrl* pTree, HTREEITEM parent,
|
2014-11-04 00:26:53 +00:00
|
|
|
DiskImgLib::DiskFS* pDiskFS, int depth)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
const DiskFS::SubVolume* pSubVol;
|
|
|
|
TargetData* pTarget;
|
|
|
|
HTREEITEM hLocalRoot;
|
|
|
|
TVITEM tvi;
|
|
|
|
TVINSERTSTRUCT tvins;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert an entry for the current item.
|
2014-12-05 01:05:48 +00:00
|
|
|
*
|
|
|
|
* The TVITEM struct wants a pointer to WCHAR* storage for the item
|
|
|
|
* text. The DiskFS only provides narrow chars, so we need to create
|
|
|
|
* some local storage for the widened version. Some calls that take a
|
|
|
|
* TVITEM allow the text to be edited, so the field is LPWSTR rather
|
|
|
|
* than LPCWSTR, but our uses don't allow editing, so we're okay
|
|
|
|
* passing it a pointer to storage inside a CString.
|
2014-11-04 00:26:53 +00:00
|
|
|
*/
|
|
|
|
pTarget = AllocTargetData();
|
|
|
|
pTarget->kind = kTargetDiskFS;
|
|
|
|
pTarget->pDiskFS = pDiskFS;
|
2014-11-18 05:13:13 +00:00
|
|
|
pTarget->pFile = NULL; // could also use volume dir for ProDOS
|
2014-11-04 00:26:53 +00:00
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
|
2015-01-15 22:21:01 +00:00
|
|
|
CString volumeId(Charset::ConvertMORToUNI(pDiskFS->GetVolumeID()));
|
Volume name and font fixes
More volume name MOR conversions. I think I got them all.
This also switches the "archive info", "add files", and "extract
files" dialogs to use the System Font. We were using "MS Sans
Serif" before, which looks a bit ratty on Windows 7 because it
doesn't take advantage of ClearType. (Apparently the ClearType
version is "Microsoft Sans Serif", though when you set the "use
system font" boolean to true it changes the font name to "MS Shell
Dlg".) The old font also seems to be missing certain glyphs, e.g.
my HFS volume name had 'TM' in it, but that just showed up as a box
(which is why, in case you were wondering, these changes ended up
together).
The new font seems to work equally well on WinXP, so I may enable
it for all dialogs in a follow-up change. As far as I can tell it
has the same font metrics -- I haven't seen anything weird looking
in the dialogs I've updated so far.
Also, bumped the version to 4.0.0-b3.
2015-01-15 19:25:26 +00:00
|
|
|
int index = fStringHolder.Add(volumeId);
|
2014-12-05 01:05:48 +00:00
|
|
|
tvi.pszText = (LPWSTR)(LPCWSTR) fStringHolder.GetAt(index);
|
2014-11-04 00:26:53 +00:00
|
|
|
tvi.cchTextMax = 0; // not needed for insertitem
|
|
|
|
// tvi.iImage = kTreeImageFolderClosed;
|
|
|
|
// tvi.iSelectedImage = kTreeImageFolderOpen;
|
|
|
|
if (pDiskFS->GetReadWriteSupported() && !pDiskFS->GetFSDamaged()) {
|
|
|
|
tvi.iImage = kTreeImageHardDriveRW;
|
|
|
|
pTarget->selectable = true;
|
|
|
|
} else {
|
|
|
|
tvi.iImage = kTreeImageHardDriveRO;
|
|
|
|
pTarget->selectable = false;
|
|
|
|
}
|
|
|
|
tvi.iSelectedImage = tvi.iImage;
|
|
|
|
tvi.lParam = (LPARAM) pTarget;
|
|
|
|
tvins.item = tvi;
|
|
|
|
tvins.hInsertAfter = parent;
|
|
|
|
tvins.hParent = parent;
|
|
|
|
hLocalRoot = pTree->InsertItem(&tvins);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hLocalRoot == NULL) {
|
2014-12-05 01:05:48 +00:00
|
|
|
LOGW("Tree root InsertItem failed");
|
2014-11-04 00:26:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan for and handle all sub-volumes.
|
|
|
|
*/
|
2014-11-18 05:13:13 +00:00
|
|
|
pSubVol = pDiskFS->GetNextSubVolume(NULL);
|
|
|
|
while (pSubVol != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
if (!AddDiskFS(pTree, hLocalRoot, pSubVol->GetDiskFS(), depth+1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pSubVol = pDiskFS->GetNextSubVolume(pSubVol);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this volume has sub-directories, and is read-write, add the subdirs
|
|
|
|
* to the tree.
|
|
|
|
*
|
|
|
|
* We use "depth" rather than "depth+1" because the first subdir entry
|
|
|
|
* (the volume dir) doesn't get its own entry. We use the disk entry
|
|
|
|
* to represent the disk's volume dir.
|
|
|
|
*/
|
|
|
|
if (fIncludeSubdirs && pDiskFS->GetReadWriteSupported() &&
|
|
|
|
!pDiskFS->GetFSDamaged())
|
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
AddSubdir(pTree, hLocalRoot, pDiskFS, NULL, depth);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're above the max expansion depth, expand the node.
|
|
|
|
*/
|
|
|
|
if (fExpandDepth == -1 || depth <= fExpandDepth)
|
|
|
|
pTree->Expand(hLocalRoot, TVE_EXPAND);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, if this is the root node, select it.
|
|
|
|
*/
|
|
|
|
if (parent == TVI_ROOT) {
|
|
|
|
pTree->Select(hLocalRoot, TVGN_CARET);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
DiskImgLib::A2File* DiskFSTree::AddSubdir(CTreeCtrl* pTree, HTREEITEM parent,
|
2014-11-04 00:26:53 +00:00
|
|
|
DiskImgLib::DiskFS* pDiskFS, DiskImgLib::A2File* pParentFile,
|
|
|
|
int depth)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
A2File* pFile;
|
|
|
|
TargetData* pTarget;
|
|
|
|
HTREEITEM hLocalRoot;
|
|
|
|
TVITEM tvi;
|
|
|
|
TVINSERTSTRUCT tvins;
|
|
|
|
|
|
|
|
pFile = pDiskFS->GetNextFile(pParentFile);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pFile == NULL && pParentFile == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
/* this can happen on an empty DOS 3.3 disk; under ProDOS, we always
|
|
|
|
have the volume entry */
|
2014-11-18 05:13:13 +00:00
|
|
|
/* note pFile will be NULL if this happens to be a subdirectory
|
2014-11-04 00:26:53 +00:00
|
|
|
positioned as the very last file on the disk */
|
2014-11-18 05:13:13 +00:00
|
|
|
return NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pParentFile == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* This is the root of the disk. We already have a DiskFS entry for
|
|
|
|
* it, so don't add a new tree item here.
|
|
|
|
*
|
|
|
|
* Check to see if this disk has a volume directory entry.
|
|
|
|
*/
|
|
|
|
if (pFile->IsVolumeDirectory()) {
|
|
|
|
pParentFile = pFile;
|
|
|
|
pFile = pDiskFS->GetNextFile(pFile);
|
|
|
|
}
|
|
|
|
hLocalRoot = parent;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Add an entry for this subdir (the "parent" entry).
|
2014-12-05 01:05:48 +00:00
|
|
|
*
|
|
|
|
* This has the same wide-vs-narrow storage issues as AddDiskFS().
|
2014-11-04 00:26:53 +00:00
|
|
|
*/
|
|
|
|
pTarget = AllocTargetData();
|
|
|
|
pTarget->kind = kTargetSubdir;
|
|
|
|
pTarget->selectable = true;
|
|
|
|
pTarget->pDiskFS = pDiskFS;
|
|
|
|
pTarget->pFile = pParentFile;
|
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
|
2014-12-05 01:05:48 +00:00
|
|
|
CString fileNameW(pParentFile->GetFileName());
|
|
|
|
int index = fStringHolder.Add(fileNameW);
|
|
|
|
tvi.pszText = (LPWSTR)(LPCWSTR) fStringHolder.GetAt(index);
|
2014-11-04 00:26:53 +00:00
|
|
|
tvi.cchTextMax = 0; // not needed for insertitem
|
|
|
|
tvi.iImage = kTreeImageFolderClosed;
|
|
|
|
tvi.iSelectedImage = kTreeImageFolderOpen;
|
|
|
|
tvi.lParam = (LPARAM) pTarget;
|
|
|
|
tvins.item = tvi;
|
|
|
|
tvins.hInsertAfter = parent;
|
|
|
|
tvins.hParent = parent;
|
|
|
|
hLocalRoot = pTree->InsertItem(&tvins);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hLocalRoot == NULL) {
|
2014-12-05 01:05:48 +00:00
|
|
|
LOGW("Tree insert '%ls' failed", tvi.pszText);
|
2014-11-18 05:13:13 +00:00
|
|
|
return NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
while (pFile != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
if (pFile->IsDirectory()) {
|
|
|
|
ASSERT(!pFile->IsVolumeDirectory());
|
|
|
|
|
|
|
|
if (pFile->GetParent() == pParentFile) {
|
|
|
|
/* this is a subdir of us */
|
|
|
|
pFile = AddSubdir(pTree, hLocalRoot, pDiskFS, pFile, depth+1);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pFile == NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
break; // out of while -- disk is done
|
|
|
|
} else {
|
|
|
|
/* not one of our subdirs; pop up a level */
|
|
|
|
break; // out of while -- subdir is done
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pFile = pDiskFS->GetNextFile(pFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* expand as appropriate */
|
|
|
|
if (fExpandDepth == -1 || depth <= fExpandDepth)
|
|
|
|
pTree->Expand(hLocalRoot, TVE_EXPAND);
|
|
|
|
|
|
|
|
return pFile;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
DiskFSTree::TargetData* DiskFSTree::AllocTargetData(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
TargetData* pNew = new TargetData;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pNew == NULL)
|
|
|
|
return NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* insert it at the head of the list, and update the head pointer */
|
|
|
|
pNew->pNext = fpTargetData;
|
|
|
|
fpTargetData = pNew;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return pNew;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void DiskFSTree::FreeAllTargetData(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
TargetData* pTarget;
|
|
|
|
TargetData* pNext;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
pTarget = fpTargetData;
|
2014-11-18 05:13:13 +00:00
|
|
|
while (pTarget != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
pNext = pTarget->pNext;
|
|
|
|
delete pTarget;
|
|
|
|
pTarget = pNext;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
fpTargetData = NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|