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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Implementation of DiskImgLib globals.
|
|
|
|
*/
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "DiskImgPriv.h"
|
|
|
|
#include "ASPI.h"
|
|
|
|
|
|
|
|
/*static*/ bool Global::fAppInitCalled = false;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
/*static*/ ASPI* Global::fpASPI = NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/* global constant */
|
|
|
|
const char* DiskImgLib::kASPIDev = "ASPI:";
|
|
|
|
|
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
|
|
|
|
2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* Perform one-time DLL initialization.
|
|
|
|
*/
|
2014-11-24 20:56:19 +00:00
|
|
|
/*static*/ DIError Global::AppInit(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
NuError nerr;
|
|
|
|
long major, minor, bug;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fAppInitCalled) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGW("DiskImg AppInit already called");
|
2014-11-04 00:26:53 +00:00
|
|
|
return kDIErrNone;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Initializing DiskImg library v%d.%d.%d",
|
2014-11-04 00:26:53 +00:00
|
|
|
kDiskImgVersionMajor, kDiskImgVersionMinor, kDiskImgVersionBug);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2014-11-04 00:26:53 +00:00
|
|
|
HMODULE hModule;
|
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 fileNameBuf[256];
|
|
|
|
hModule = ::GetModuleHandle(L"DiskImg4.dll");
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hModule != NULL &&
|
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
|
|
|
::GetModuleFileName(hModule, fileNameBuf,
|
|
|
|
sizeof(fileNameBuf) / sizeof(WCHAR)) != 0)
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
|
|
|
// GetModuleHandle does not increase ref count, so no need to release
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGD("DiskImg DLL loaded from '%ls'", fileNameBuf);
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGW("Unable to get DiskImg DLL filename");
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* Make sure we're linked against a compatible version of NufxLib.
|
|
|
|
*/
|
|
|
|
nerr = NuGetVersion(&major, &minor, &bug, NULL, NULL);
|
|
|
|
if (nerr != kNuErrNone) {
|
2014-11-18 01:54:34 +00:00
|
|
|
LOGE("Unable to get version number from NufxLib.");
|
2014-11-04 00:26:53 +00:00
|
|
|
return kDIErrNufxLibInitFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (major != kNuVersionMajor || minor < kNuVersionMinor) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGE("Unexpected NufxLib version %ld.%ld.%ld",
|
2014-11-04 00:26:53 +00:00
|
|
|
major, minor, bug);
|
|
|
|
return kDIErrNufxLibInitFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do one-time init over in the DiskImg class.
|
|
|
|
*/
|
|
|
|
DiskImg::CalcNibbleInvTables();
|
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
|
|
|
#if defined(HAVE_WINDOWS_CDROM) && defined(WANT_ASPI)
|
2014-11-04 00:26:53 +00:00
|
|
|
if (kAlwaysTryASPI || IsWin9x()) {
|
|
|
|
fpASPI = new ASPI;
|
|
|
|
if (fpASPI->Init() != kDIErrNone) {
|
|
|
|
delete fpASPI;
|
2014-11-18 05:13:13 +00:00
|
|
|
fpASPI = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGD("DiskImg HasSPTI=%d HasASPI=%d", GetHasSPTI(), GetHasASPI());
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
fAppInitCalled = true;
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return kDIErrNone;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform cleanup at application shutdown time.
|
|
|
|
*/
|
2014-11-24 20:56:19 +00:00
|
|
|
/*static*/ DIError Global::AppCleanup(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("DiskImgLib cleanup");
|
2014-11-04 00:26:53 +00:00
|
|
|
delete fpASPI;
|
|
|
|
return kDIErrNone;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple getters.
|
|
|
|
*
|
|
|
|
* SPTI is enabled if we're in Win2K *and* ASPI isn't loaded. If ASPI is
|
|
|
|
* loaded, it can interfere with SPTI, so we want to stick with one or
|
|
|
|
* the other.
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
2014-11-18 05:13:13 +00:00
|
|
|
/*static*/ bool Global::GetHasSPTI(void) { return !IsWin9x() && fpASPI == NULL; }
|
|
|
|
/*static*/ bool Global::GetHasASPI(void) { return fpASPI != NULL; }
|
2007-03-27 17:47:10 +00:00
|
|
|
/*static*/ unsigned long Global::GetASPIVersion(void) {
|
2014-11-18 05:13:13 +00:00
|
|
|
assert(fpASPI != NULL);
|
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
|
|
|
#ifdef WANT_ASPI
|
2014-11-04 00:26:53 +00:00
|
|
|
return fpASPI->GetVersion();
|
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
|
|
|
#else
|
|
|
|
return 123456789;
|
|
|
|
#endif
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*static*/ bool Global::GetHasSPTI(void) { return false; }
|
|
|
|
/*static*/ bool Global::GetHasASPI(void) { return false; }
|
|
|
|
/*static*/ unsigned long Global::GetASPIVersion(void) { assert(false); return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return current library versions.
|
|
|
|
*/
|
2014-11-24 20:56:19 +00:00
|
|
|
/*static*/ void Global::GetVersion(long* pMajor, long* pMinor, long* pBug)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pMajor != NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
*pMajor = kDiskImgVersionMajor;
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pMinor != NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
*pMinor = kDiskImgVersionMinor;
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pBug != NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
*pBug = kDiskImgVersionBug;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pointer to debug message handler function.
|
|
|
|
*/
|
2014-11-18 05:13:13 +00:00
|
|
|
/*static*/ Global::DebugMsgHandler Global::gDebugMsgHandler = NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the debug message handler. The previous handler is returned.
|
|
|
|
*/
|
2014-11-24 20:56:19 +00:00
|
|
|
Global::DebugMsgHandler Global::SetDebugMsgHandler(DebugMsgHandler handler)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
DebugMsgHandler oldHandler;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
oldHandler = gDebugMsgHandler;
|
|
|
|
gDebugMsgHandler = handler;
|
|
|
|
return oldHandler;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a debug message to the debug message handler.
|
|
|
|
*
|
|
|
|
* Even if _DEBUG_MSGS is disabled we can still get here from the NuFX error
|
|
|
|
* handler.
|
|
|
|
*/
|
2014-11-24 20:56:19 +00:00
|
|
|
/*static*/ void Global::PrintDebugMsg(const char* file, int line, const char* fmt, ...)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 05:13:13 +00:00
|
|
|
if (gDebugMsgHandler == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* This can happen if the app decides to bail with an exit()
|
|
|
|
* call. I'm not sure what's zapping the pointer.
|
|
|
|
*
|
|
|
|
* We get here on "-install" or "-uninstall", which really
|
|
|
|
* should be using a more Windows-friendly exit strategy.
|
|
|
|
*/
|
|
|
|
DebugBreak();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[512];
|
2007-03-27 17:47:10 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
#if defined(HAVE_VSNPRINTF)
|
2014-11-04 00:26:53 +00:00
|
|
|
(void) vsnprintf(buf, sizeof(buf), fmt, args);
|
2007-03-27 17:47:10 +00:00
|
|
|
#elif defined(HAVE__VSNPRINTF)
|
2014-11-04 00:26:53 +00:00
|
|
|
(void) _vsnprintf(buf, sizeof(buf), fmt, args);
|
2007-03-27 17:47:10 +00:00
|
|
|
#else
|
|
|
|
# error "hosed"
|
|
|
|
#endif
|
|
|
|
va_end(args);
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
buf[sizeof(buf)-1] = '\0';
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
(*gDebugMsgHandler)(file, line, buf);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|