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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Windows Registry operations.
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2014-12-11 21:53:02 +00:00
|
|
|
#ifdef CAN_UPDATE_FILE_ASSOC
|
2007-03-27 17:47:10 +00:00
|
|
|
#include "Registry.h"
|
|
|
|
#include "Main.h"
|
|
|
|
#include "MyApp.h"
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
#define kCompanyName L"faddenSoft"
|
|
|
|
|
|
|
|
#if 0
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
#define kRegAppName L"CiderPress"
|
|
|
|
#define kRegExeName L"CiderPress.exe"
|
2007-03-27 17:47:10 +00:00
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
static const WCHAR kRegKeyCPKVersions[] = L"vrs";
|
|
|
|
static const WCHAR kRegKeyCPKExpire[] = L"epr";
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Application path. Add two keys:
|
|
|
|
*
|
2014-11-04 00:26:53 +00:00
|
|
|
* (default) = FullPathName
|
|
|
|
* Full pathname of the executable file.
|
|
|
|
* Path = Path
|
|
|
|
* The $PATH that will be in effect when the program starts (but only if
|
|
|
|
* launched from the Windows explorer).
|
2007-03-27 17:47:10 +00:00
|
|
|
*/
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
static const WCHAR kAppKeyBase[] =
|
|
|
|
L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" kRegExeName;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local settings. App stuff goes in the per-user key, registration info is
|
|
|
|
* in the per-machine key.
|
|
|
|
*/
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
static const WCHAR kMachineSettingsBaseKey[] =
|
|
|
|
L"HKEY_LOCAL_MACHINE\\SOFTWARE\\" kCompanyName L"\\" kRegAppName;
|
|
|
|
static const WCHAR kUserSettingsBaseKey[] =
|
|
|
|
L"HKEY_CURRENT_USER\\Software\\" kCompanyName L"\\" kRegAppName;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
static const WCHAR kRegKeyCPKStr[] = L"CPK";
|
|
|
|
#endif
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
2014-12-16 05:57:09 +00:00
|
|
|
* ProgID fields.
|
2007-03-27 17:47:10 +00:00
|
|
|
*
|
2014-12-16 05:57:09 +00:00
|
|
|
* See http://msdn.microsoft.com/en-us/library/windows/desktop/cc144152%28v=vs.85%29.aspx
|
2007-03-27 17:47:10 +00:00
|
|
|
*/
|
2014-12-16 05:57:09 +00:00
|
|
|
|
|
|
|
static const WCHAR kDefaultIcon[] = L"DefaultIcon";
|
|
|
|
static const WCHAR kFriendlyTypeName[] = L"FriendlyTypeName";
|
|
|
|
static const WCHAR kInfoTip[] = L"InfoTip";
|
|
|
|
|
|
|
|
static const WCHAR kShellOpenCommand[] = L"\\shell\\open\\command";
|
|
|
|
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
2014-12-16 05:57:09 +00:00
|
|
|
* ProgID key names.
|
|
|
|
*
|
|
|
|
* We used to open HKEY_CLASSES_ROOT, which provides a "merged" view of
|
|
|
|
* HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes.
|
|
|
|
* The HKLM entries provided defaults for all users on the machine, while the
|
|
|
|
* HKCU entries were specific to the current user.
|
|
|
|
*
|
|
|
|
* It appears that Windows no longer likes it when executables other than the
|
|
|
|
* app installer (which can run privileged) mess with HKLM, so we just work
|
|
|
|
* with HKCU directly now.
|
2007-03-27 17:47:10 +00:00
|
|
|
*/
|
2014-12-16 05:57:09 +00:00
|
|
|
static const WCHAR kProgIdKeyNuFX[] = L"CiderPress.NuFX.4";
|
|
|
|
static const WCHAR kProgIdKeyDiskImage[] = L"CiderPress.DiskImage.4";
|
|
|
|
static const WCHAR kProgIdKeyBinaryII[] = L"CiderPress.BinaryII.4";
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
/* file associations go here under HKCU */
|
|
|
|
static const WCHAR kFileAssocBase[] = L"Software\\Classes";
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Table of file type associations. They will appear in the UI in the same
|
|
|
|
* order that they appear here, so try to maintain alphabetical order.
|
|
|
|
*/
|
|
|
|
const MyRegistry::FileTypeAssoc MyRegistry::kFileTypeAssoc[] = {
|
2014-12-16 05:57:09 +00:00
|
|
|
{ L".2MG", kProgIdKeyDiskImage },
|
|
|
|
{ L".APP", kProgIdKeyDiskImage },
|
|
|
|
{ L".BNY", kProgIdKeyBinaryII },
|
|
|
|
{ L".BQY", kProgIdKeyBinaryII },
|
|
|
|
{ L".BSE", kProgIdKeyNuFX },
|
|
|
|
{ L".BXY", kProgIdKeyNuFX },
|
|
|
|
{ L".D13", kProgIdKeyDiskImage },
|
|
|
|
{ L".DDD", kProgIdKeyDiskImage },
|
|
|
|
{ L".DO", kProgIdKeyDiskImage },
|
|
|
|
{ L".DSK", kProgIdKeyDiskImage },
|
|
|
|
{ L".FDI", kProgIdKeyDiskImage },
|
|
|
|
{ L".HDV", kProgIdKeyDiskImage },
|
|
|
|
{ L".IMG", kProgIdKeyDiskImage },
|
|
|
|
{ L".NIB", kProgIdKeyDiskImage },
|
|
|
|
{ L".PO", kProgIdKeyDiskImage },
|
|
|
|
{ L".SDK", kProgIdKeyDiskImage },
|
|
|
|
{ L".SEA", kProgIdKeyNuFX },
|
|
|
|
{ L".SHK", kProgIdKeyNuFX },
|
|
|
|
// { L".DC", kProgIdKeyDiskImage },
|
|
|
|
// { L".DC6", kProgIdKeyDiskImage },
|
|
|
|
// { L".GZ", kProgIdKeyDiskImage },
|
|
|
|
// { L".NB2", kProgIdKeyDiskImage },
|
|
|
|
// { L".RAW", kProgIdKeyDiskImage },
|
|
|
|
// { L".ZIP", kProgIdKeyDiskImage },
|
2007-03-27 17:47:10 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
#if 0
|
2007-03-27 17:47:10 +00:00
|
|
|
static const struct {
|
2014-11-04 00:26:53 +00:00
|
|
|
const char* user;
|
|
|
|
const char* reg;
|
2007-03-27 17:47:10 +00:00
|
|
|
} gBadKeys[] = {
|
2014-11-04 00:26:53 +00:00
|
|
|
{ "Nimrod Bonehead", "CP1-68C069-62CC9444" },
|
|
|
|
{ "Connie Tan", "CP1-877B2C-A428FFD6" },
|
2007-03-27 17:47:10 +00:00
|
|
|
};
|
2014-12-16 05:57:09 +00:00
|
|
|
#endif
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* One-time install/uninstall
|
2007-03-27 17:47:10 +00:00
|
|
|
* ==========================================================================
|
|
|
|
*/
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MyRegistry::OneTimeInstall(void) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
/* start by stomping on our ProgIDs */
|
|
|
|
LOGI(" Removing ProgIDs");
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyNuFX);
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyDiskImage);
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyBinaryII);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
/* configure the ProgIDs */
|
2014-11-04 00:26:53 +00:00
|
|
|
FixBasicSettings();
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* configure extensions */
|
2014-12-16 05:57:09 +00:00
|
|
|
for (int i = 0; i < NELEM(kFileTypeAssoc); i++) {
|
2014-11-04 00:26:53 +00:00
|
|
|
HKEY hExtKey;
|
2014-12-16 05:57:09 +00:00
|
|
|
LSTATUS res = RegOpenKeyEx(hClassesKey, kFileTypeAssoc[i].ext, 0,
|
2014-11-04 00:26:53 +00:00
|
|
|
KEY_READ, &hExtKey);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" Found existing HKCU\\%ls\\'%ls', leaving alone",
|
|
|
|
kFileAssocBase, kFileTypeAssoc[i].ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
RegCloseKey(hExtKey);
|
|
|
|
} else if (res == ERROR_FILE_NOT_FOUND) {
|
2014-12-16 05:57:09 +00:00
|
|
|
OwnExtension(kFileTypeAssoc[i].ext, kFileTypeAssoc[i].progId);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW(" Got error %lu opening HKCU\\%ls\\'%ls', leaving alone",
|
|
|
|
res, kFileAssocBase, kFileTypeAssoc[i].ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-16 05:57:09 +00:00
|
|
|
|
|
|
|
RegCloseKey(hClassesKey);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MyRegistry::OneTimeUninstall(void) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
/* drop any associations we hold */
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < NELEM(kFileTypeAssoc); i++) {
|
|
|
|
CString ext, handler;
|
|
|
|
bool ours;
|
|
|
|
|
|
|
|
GetFileAssoc(i, &ext, &handler, &ours);
|
|
|
|
if (ours) {
|
|
|
|
DisownExtension(ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
/* remove our ProgIDs */
|
|
|
|
LOGI(" Removing ProgIDs");
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyNuFX);
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyDiskImage);
|
|
|
|
RegDeleteKeyHKCU(kProgIdKeyBinaryII);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* Shareware registration logic
|
2007-03-27 17:47:10 +00:00
|
|
|
* ==========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* [removed] */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* Windows shell game
|
2007-03-27 17:47:10 +00:00
|
|
|
* ==========================================================================
|
|
|
|
*/
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
const WCHAR* MyRegistry::GetAppRegistryKey(void) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
return kCompanyName;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
bool MyRegistry::IsOurProgId(const WCHAR* progIdKeyName) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
return (wcsicmp(progIdKeyName, kProgIdKeyNuFX) == 0 ||
|
|
|
|
wcsicmp(progIdKeyName, kProgIdKeyDiskImage) == 0 ||
|
|
|
|
wcsicmp(progIdKeyName, kProgIdKeyBinaryII) == 0);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MyRegistry::FixBasicSettings(void) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
2014-12-16 05:57:09 +00:00
|
|
|
* Fix the basic registry settings, e.g. our ProgID classes.
|
2014-11-21 21:18:20 +00:00
|
|
|
*
|
|
|
|
* We don't overwrite values that already exist. We want to hold on to the
|
|
|
|
* installer's settings, which should get whacked if the program is
|
|
|
|
* uninstalled or reinstalled. This is here for "installer-less" environments
|
|
|
|
* and to cope with registry damage.
|
|
|
|
*/
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
const WCHAR* exeName = gMyApp.GetExeFileName();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(exeName != NULL && wcslen(exeName) > 0);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI("Fixing any missing file type ProgID entries in registry");
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
ConfigureProgId(kProgIdKeyNuFX, L"NuFX Archive (CiderPress)", exeName, 1);
|
|
|
|
ConfigureProgId(kProgIdKeyBinaryII, L"Binary II (CiderPress)", exeName, 2);
|
|
|
|
ConfigureProgId(kProgIdKeyDiskImage, L"Disk Image (CiderPress)", exeName, 3);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
void MyRegistry::ConfigureProgId(const WCHAR* progIdKeyName, const WCHAR* descr,
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
const WCHAR* exeName, int iconIdx) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" ConfigureProgId '%ls' for '%ls'", progIdKeyName, exeName);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
2014-11-18 05:13:13 +00:00
|
|
|
HKEY hAppKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
LOGW(" ConfigureProgId failed to open HKCU");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD disp;
|
2014-12-11 21:53:02 +00:00
|
|
|
LONG result;
|
2014-12-16 05:57:09 +00:00
|
|
|
if ((result = RegCreateKeyEx(hClassesKey, progIdKeyName, 0, REG_NONE,
|
2014-11-04 00:26:53 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
2014-12-16 05:57:09 +00:00
|
|
|
&hAppKey, &disp)) == ERROR_SUCCESS)
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
if (disp == REG_CREATED_NEW_KEY) {
|
|
|
|
LOGD(" Created new key for %ls", progIdKeyName);
|
|
|
|
} else if (disp == REG_OPENED_EXISTING_KEY) {
|
|
|
|
LOGD(" Opened existing key for %ls", progIdKeyName);
|
|
|
|
} else {
|
|
|
|
LOGD(" Odd RegCreateKeyEx result 0x%lx", disp);
|
|
|
|
}
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
ConfigureProgIdCommand(hAppKey, descr, exeName);
|
|
|
|
|
|
|
|
// Configure default entry and "friendly" type name. The friendly
|
|
|
|
// name takes precedence (as tested on Win7), but the default entry
|
|
|
|
// is set for backward compatibility.
|
|
|
|
if (RegSetValueEx(hAppKey, L"", 0, REG_SZ, (const BYTE*) descr,
|
|
|
|
(wcslen(descr)+1) * sizeof(WCHAR)) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
LOGW(" WARNING: unable to set ProgID default to '%ls'", descr);
|
|
|
|
}
|
|
|
|
if (RegSetValueEx(hAppKey, kFriendlyTypeName, 0, REG_SZ,
|
|
|
|
(const BYTE*) descr,
|
|
|
|
(wcslen(descr)+1) * sizeof(WCHAR)) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
LOGW(" WARNING: unable to set ProgID friendly name to '%ls'", descr);
|
|
|
|
}
|
|
|
|
//if (RegSetValueEx(hAppKey, kInfoTip, 0, REG_SZ,
|
|
|
|
// (const BYTE*) infoTip,
|
|
|
|
// (wcslen(infoTip)+1) * sizeof(WCHAR)) != ERROR_SUCCESS)
|
|
|
|
//{
|
|
|
|
// LOGW(" WARNING: unable to set ProgID info tip to '%ls'", infoTip);
|
|
|
|
//}
|
|
|
|
|
|
|
|
// Configure the default icon field. This is a DefaultIcon entry
|
|
|
|
// with a (Default) name.
|
|
|
|
HKEY hIconKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
if (RegCreateKeyEx(hAppKey, kDefaultIcon, 0, REG_NONE,
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
2014-12-16 05:57:09 +00:00
|
|
|
&hIconKey, NULL) == ERROR_SUCCESS)
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
|
|
|
DWORD type, size;
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
unsigned char buf[512];
|
2014-11-04 00:26:53 +00:00
|
|
|
long res;
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
size = sizeof(buf); // size in bytes
|
2014-11-18 05:13:13 +00:00
|
|
|
res = RegQueryValueEx(hIconKey, L"", NULL, &type, buf, &size);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS && size > 1) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" Icon for '%ls' already exists, not altering",
|
|
|
|
progIdKeyName);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
|
|
|
CString iconStr;
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
iconStr.Format(L"%ls,%d", exeName, iconIdx);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
if (RegSetValueEx(hIconKey, L"", 0, REG_SZ,
|
2014-11-25 22:34:14 +00:00
|
|
|
(const BYTE*)(LPCWSTR) iconStr,
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
wcslen(iconStr) * sizeof(WCHAR)) == ERROR_SUCCESS)
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" Set icon for '%ls' to '%ls'", progIdKeyName,
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
(LPCWSTR) iconStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-11 21:53:02 +00:00
|
|
|
LOGW(" WARNING: unable to set DefaultIcon for '%ls' to '%ls'",
|
2014-12-16 05:57:09 +00:00
|
|
|
progIdKeyName, (LPCWSTR) iconStr);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-16 05:57:09 +00:00
|
|
|
|
|
|
|
RegCloseKey(hIconKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW(" WARNING: couldn't set up DefaultIcon for '%ls'", progIdKeyName);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW(" WARNING: couldn't create ProgId='%ls' (err=%ld)",
|
|
|
|
progIdKeyName, result);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hAppKey);
|
2014-12-16 05:57:09 +00:00
|
|
|
RegCloseKey(hClassesKey);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
void MyRegistry::ConfigureProgIdCommand(HKEY hAppKey, const WCHAR* descr,
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
const WCHAR* exeName) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
HKEY hShellKey, hOpenKey, hCommandKey;
|
|
|
|
DWORD dw;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(hAppKey != NULL);
|
|
|
|
ASSERT(descr != NULL);
|
|
|
|
ASSERT(exeName != NULL);
|
|
|
|
hShellKey = hOpenKey = hCommandKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
// TODO: I believe we can do this with a single call -- it should create
|
|
|
|
// the intermediate path elements for us.
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
if (RegCreateKeyEx(hAppKey, L"shell", 0, REG_NONE,
|
2014-11-04 00:26:53 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
|
|
|
&hShellKey, &dw) == ERROR_SUCCESS)
|
|
|
|
{
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
if (RegCreateKeyEx(hShellKey, L"open", 0, REG_NONE,
|
2014-11-04 00:26:53 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
|
|
|
&hOpenKey, &dw) == ERROR_SUCCESS)
|
|
|
|
{
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
if (RegCreateKeyEx(hOpenKey, L"command", 0, REG_NONE,
|
2014-11-04 00:26:53 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
|
|
|
&hCommandKey, &dw) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD type, size;
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
WCHAR buf[MAX_PATH+8];
|
2014-11-04 00:26:53 +00:00
|
|
|
long res;
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
size = sizeof(buf); // size in bytes
|
2014-11-18 05:13:13 +00:00
|
|
|
res = RegQueryValueEx(hCommandKey, L"", NULL, &type, (LPBYTE) buf,
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
&size);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS && size > 1) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" Command already exists, not altering ('%ls')", buf);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
|
|
|
CString openCmd;
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
openCmd.Format(L"\"%ls\" \"%%1\"", exeName);
|
|
|
|
if (RegSetValueEx(hCommandKey, L"", 0, REG_SZ,
|
|
|
|
(LPBYTE)(LPCWSTR) openCmd,
|
|
|
|
wcslen(openCmd) * sizeof(WCHAR)) == ERROR_SUCCESS)
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
2014-11-19 22:54:24 +00:00
|
|
|
LOGI(" Set command to '%ls'", (LPCWSTR) openCmd);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-11-19 22:54:24 +00:00
|
|
|
LOGW(" WARNING: unable to set open cmd '%ls'",
|
|
|
|
(LPCWSTR) openCmd);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 22:54:24 +00:00
|
|
|
RegCloseKey(hCommandKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2014-11-19 22:54:24 +00:00
|
|
|
RegCloseKey(hOpenKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2014-11-19 22:54:24 +00:00
|
|
|
RegCloseKey(hShellKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int MyRegistry::GetNumFileAssocs(void) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
return NELEM(kFileTypeAssoc);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MyRegistry::GetFileAssoc(int idx, CString* pExt, CString* pHandler,
|
2014-11-04 00:26:53 +00:00
|
|
|
bool* pOurs) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* We check to see if the file extension is associated with one of our
|
2014-12-16 05:57:09 +00:00
|
|
|
* ProgID keys. We don't bother to check whether the ProgID keys
|
|
|
|
* are still associated with CiderPress, since nobody should be
|
2014-11-21 21:18:20 +00:00
|
|
|
* messing with those.
|
|
|
|
*
|
|
|
|
* BUG: we should be checking to see what the shell actually does to
|
|
|
|
* take into account the overrides that users can set.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
ASSERT(idx >= 0 && idx < NELEM(kFileTypeAssoc));
|
|
|
|
|
|
|
|
*pExt = kFileTypeAssoc[idx].ext;
|
2014-12-16 05:57:09 +00:00
|
|
|
*pHandler = L"";
|
|
|
|
*pOurs = false;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
LOGW("GetFileAssoc failed to open HKCU");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CString progIdKeyName;
|
2014-11-18 05:13:13 +00:00
|
|
|
HKEY hExtKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
long res = RegOpenKeyEx(hClassesKey, *pExt, 0, KEY_READ, &hExtKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
WCHAR buf[MAX_PATH]; // somewhat arbitrary
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
DWORD size = sizeof(buf); // size in bytes
|
2014-12-16 05:57:09 +00:00
|
|
|
DWORD type;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
res = RegQueryValueEx(hExtKey, L"", NULL, &type, (LPBYTE)buf, &size);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGD(" GetFileAssoc %d got '%ls'", idx, buf);
|
|
|
|
progIdKeyName = buf;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
if (GetAssocAppName(progIdKeyName, pHandler) != 0)
|
|
|
|
*pHandler = progIdKeyName;
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW("RegQueryValueEx failed on '%ls'", (LPCWSTR) *pExt);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-19 22:54:24 +00:00
|
|
|
LOGW(" RegOpenKeyEx failed on '%ls'", (LPCWSTR) *pExt);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
if (!pHandler->IsEmpty()) {
|
|
|
|
*pOurs = IsOurProgId(progIdKeyName);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hExtKey);
|
2014-12-16 05:57:09 +00:00
|
|
|
RegCloseKey(hClassesKey);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
int MyRegistry::GetAssocAppName(const CString& progIdKeyName, CString* pCmd) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
HKEY hAppKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
int result = -1;
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
LOGW("GetAssocAppName failed to open HKCU");
|
|
|
|
return result;
|
|
|
|
}
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
CString keyName = progIdKeyName + kShellOpenCommand;
|
|
|
|
|
|
|
|
long res = RegOpenKeyEx(hClassesKey, keyName, 0, KEY_READ, &hAppKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
WCHAR buf[260];
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
DWORD type;
|
|
|
|
DWORD size = sizeof(buf); // size in bytes
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
res = RegQueryValueEx(hAppKey, L"", NULL, &type, (LPBYTE) buf, &size);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
CString cmd(buf);
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
/* cut it down to just the EXE name */
|
|
|
|
ReduceToToken(&cmd);
|
|
|
|
|
|
|
|
pos = cmd.ReverseFind('\\');
|
|
|
|
if (pos != -1 && pos != cmd.GetLength()-1) {
|
|
|
|
cmd = cmd.Right(cmd.GetLength() - pos -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pCmd = cmd;
|
|
|
|
result = 0;
|
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW("Unable to open %ls for '%ls'", (LPCWSTR) kShellOpenCommand,
|
|
|
|
(LPCWSTR) progIdKeyName);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CString errBuf;
|
|
|
|
GetWin32ErrorString(res, &errBuf);
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW("Unable to open ProgId key '%ls' (%ls)",
|
2014-11-19 22:54:24 +00:00
|
|
|
(LPCWSTR) keyName, (LPCWSTR) errBuf);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hAppKey);
|
2014-12-16 05:57:09 +00:00
|
|
|
RegCloseKey(hClassesKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
return result;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void MyRegistry::ReduceToToken(CString* pStr) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
WCHAR* argv[1];
|
2014-11-04 00:26:53 +00:00
|
|
|
int argc = 1;
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
WCHAR* mangle = wcsdup(*pStr);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
VectorizeString(mangle, argv, &argc);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (argc == 1)
|
|
|
|
*pStr = argv[0];
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
free(mangle);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int MyRegistry::SetFileAssoc(int idx, bool wantIt) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* Set the state of a file association. There are four possibilities:
|
|
|
|
*
|
|
|
|
* - We own it, we want to keep owning it: do nothing.
|
|
|
|
* - We don't own it, we want to keep not owning it: do nothing.
|
|
|
|
* - We own it, we don't want it anymore: remove ".xxx" entry.
|
|
|
|
* - We don't own it, we want to own it: remove ".xxx" entry and replace it.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, nonzero on failure.
|
|
|
|
*/
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
const WCHAR* ext;
|
2014-11-04 00:26:53 +00:00
|
|
|
bool weOwnIt;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
ASSERT(idx >= 0 && idx < NELEM(kFileTypeAssoc));
|
|
|
|
|
|
|
|
ext = kFileTypeAssoc[idx].ext;
|
|
|
|
weOwnIt = GetAssocState(ext);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("SetFileAssoc: ext='%ls' own=%d want=%d", ext, weOwnIt, wantIt);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (weOwnIt && !wantIt) {
|
|
|
|
/* reset it */
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" SetFileAssoc: clearing '%ls'", ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
result = DisownExtension(ext);
|
|
|
|
} else if (!weOwnIt && wantIt) {
|
|
|
|
/* take it */
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" SetFileAssoc: taking '%ls'", ext);
|
2014-12-16 05:57:09 +00:00
|
|
|
result = OwnExtension(ext, kFileTypeAssoc[idx].progId);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" SetFileAssoc: do nothing with '%ls'", ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
bool MyRegistry::GetAssocState(const WCHAR* ext) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
WCHAR buf[260];
|
2014-11-18 05:13:13 +00:00
|
|
|
HKEY hExtKey = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
int res;
|
|
|
|
bool result = false;
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
LOGW("GetAssocState failed to open HKCU");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = RegOpenKeyEx(hClassesKey, ext, 0, KEY_READ, &hExtKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
DWORD type;
|
|
|
|
DWORD size = sizeof(buf); // size in bytes
|
2014-11-18 05:13:13 +00:00
|
|
|
res = RegQueryValueEx(hExtKey, L"", NULL, &type, (LPBYTE) buf, &size);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS && type == REG_SZ) {
|
2014-12-16 05:57:09 +00:00
|
|
|
/* compare it to known ProgID values */
|
|
|
|
LOGD(" Found '%ls', testing '%ls'", ext, buf);
|
|
|
|
if (IsOurProgId((WCHAR*)buf))
|
2014-11-04 00:26:53 +00:00
|
|
|
result = true;
|
|
|
|
}
|
2014-11-19 22:54:24 +00:00
|
|
|
RegCloseKey(hExtKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2014-12-16 05:57:09 +00:00
|
|
|
RegCloseKey(hClassesKey);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
return result;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int MyRegistry::DisownExtension(const WCHAR* ext) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(ext != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(ext[0] == '.');
|
2014-11-18 05:13:13 +00:00
|
|
|
if (ext == NULL || wcslen(ext) < 2)
|
2014-11-04 00:26:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
if (RegDeleteKeyHKCU(ext) == ERROR_SUCCESS) {
|
|
|
|
LOGI(" HKCU\\%ls\\%ls subtree deleted", kFileAssocBase, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW(" Failed deleting HKCU\\%ls\\'%ls'", kFileAssocBase, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
int MyRegistry::OwnExtension(const WCHAR* ext, const WCHAR* progIdKeyName) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(ext != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(ext[0] == '.');
|
2014-11-18 05:13:13 +00:00
|
|
|
if (ext == NULL || wcslen(ext) < 2)
|
2014-11-04 00:26:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
HKEY hClassesKey = NULL;
|
2014-11-18 05:13:13 +00:00
|
|
|
HKEY hExtKey = NULL;
|
2014-12-16 05:57:09 +00:00
|
|
|
int result = -1;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
if (OpenHKCUSoftwareClasses(&hClassesKey) != ERROR_SUCCESS) {
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the old key (which might be a hierarchy)
|
|
|
|
DWORD res = RegDeleteKeyNT(hClassesKey, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" HKCU\\%ls\\%ls subtree deleted", kFileAssocBase, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else if (res == ERROR_FILE_NOT_FOUND) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" No HKCU\\%ls\\%ls subtree to delete", kFileAssocBase, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW(" Failed deleting HKCU\\%ls\\'%ls'", kFileAssocBase, ext);
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
// set the new key
|
|
|
|
DWORD dw;
|
|
|
|
if (RegCreateKeyEx(hClassesKey, ext, 0, REG_NONE,
|
2014-11-04 00:26:53 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
|
|
|
|
&hExtKey, &dw) == ERROR_SUCCESS)
|
|
|
|
{
|
2014-12-16 05:57:09 +00:00
|
|
|
// default entry gets the ProgID key name
|
|
|
|
res = RegSetValueEx(hExtKey, L"", 0, REG_SZ, (LPBYTE) progIdKeyName,
|
|
|
|
(wcslen(progIdKeyName)+1) * sizeof(WCHAR));
|
2014-11-04 00:26:53 +00:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGI(" Set '%ls' to '%ls'", ext, progIdKeyName);
|
2014-11-04 00:26:53 +00:00
|
|
|
result = 0;
|
|
|
|
} else {
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGW("Failed setting '%ls' to '%ls' (res=%d)",
|
|
|
|
ext, progIdKeyName, res);
|
2014-11-04 00:26:53 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
bail:
|
2014-11-04 00:26:53 +00:00
|
|
|
RegCloseKey(hExtKey);
|
2014-12-16 05:57:09 +00:00
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD MyRegistry::OpenHKCUSoftwareClasses(HKEY* phKey) const
|
|
|
|
{
|
|
|
|
DWORD result = RegOpenKeyEx(HKEY_CURRENT_USER, kFileAssocBase, 0,
|
|
|
|
KEY_READ, phKey);
|
|
|
|
if (result != ERROR_SUCCESS) {
|
|
|
|
LOGW("Unable to open HKEY_CURRENT_USER \\ '%ls' for reading",
|
|
|
|
(LPCWSTR) kFileAssocBase);
|
|
|
|
}
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return result;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
DWORD MyRegistry::RegDeleteKeyHKCU(const WCHAR* partialKeyName) const
|
|
|
|
{
|
|
|
|
HKEY hClassesKey;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
result = OpenHKCUSoftwareClasses(&hClassesKey);
|
|
|
|
if (result != ERROR_SUCCESS) { return result; }
|
|
|
|
|
|
|
|
result = RegDeleteKeyNT(hClassesKey, partialKeyName);
|
|
|
|
RegCloseKey(hClassesKey);
|
|
|
|
if (result != ERROR_SUCCESS) {
|
|
|
|
LOGW("RegDeleteKeyNT failed (err=%lu)", result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
// (This comes from the MSDN sample sources.)
|
|
|
|
//
|
2014-12-16 05:57:09 +00:00
|
|
|
// Recursively delete a key and any sub-keys.
|
|
|
|
//
|
2007-03-27 17:47:10 +00:00
|
|
|
// The sample code makes no attempt to check or recover from partial
|
|
|
|
// deletions.
|
|
|
|
//
|
|
|
|
// A registry key that is opened by an application can be deleted
|
|
|
|
// without error by another application in both Windows 95 and
|
|
|
|
// Windows NT. This is by design.
|
|
|
|
//
|
2014-11-04 00:26:53 +00:00
|
|
|
#define MAX_KEY_LENGTH 256 // not in any header I can find ++ATM
|
2014-11-21 21:18:20 +00:00
|
|
|
DWORD MyRegistry::RegDeleteKeyNT(HKEY hStartKey, LPCTSTR pKeyName) const
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
DWORD dwRtn, dwSubKeyLength;
|
|
|
|
LPTSTR pSubKey = NULL;
|
|
|
|
TCHAR szSubKey[MAX_KEY_LENGTH]; // (256) this should be dynamic.
|
|
|
|
HKEY hKey;
|
|
|
|
|
2014-12-16 05:57:09 +00:00
|
|
|
LOGD("RegDeleteKeyNT %p '%ls'", hStartKey, (LPCWSTR) pKeyName);
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
// Do not allow NULL or empty key name
|
|
|
|
if ( pKeyName && lstrlen(pKeyName))
|
|
|
|
{
|
|
|
|
if( (dwRtn=RegOpenKeyEx(hStartKey,pKeyName,
|
|
|
|
0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey )) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
while (dwRtn == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
dwSubKeyLength = MAX_KEY_LENGTH;
|
|
|
|
dwRtn=RegEnumKeyEx(
|
|
|
|
hKey,
|
|
|
|
0, // always index zero, because we're deleting it
|
|
|
|
szSubKey,
|
|
|
|
&dwSubKeyLength,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if(dwRtn == ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
dwRtn = RegDeleteKey(hStartKey, pKeyName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(dwRtn == ERROR_SUCCESS)
|
|
|
|
dwRtn=RegDeleteKeyNT(hKey, szSubKey);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
// Do not save return code because error
|
|
|
|
// has already occurred
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dwRtn = ERROR_BADKEY;
|
|
|
|
|
|
|
|
return dwRtn;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-12-11 21:53:02 +00:00
|
|
|
#endif
|