Compare commits

..

33 Commits

Author SHA1 Message Date
Diomendius
ed4eb8e1f7 Use temporary staging dirs when building resources
This allows intermediate build artifacts to be cleaned up without
specifying them individually as BYPRODUCTS.

When building a data file <name>, all files are first built under
tmp/<name> before the target itself is moved from tmp/<name>/<name> to
Packaged/<name>.

add_house_file() could also be modified in this way, but it wouldn't
reduce the boilerplate by much, so it's probably not worth it.
2024-08-06 17:52:33 +12:00
Diomendius
c8e3e8683b Add deps in source tree to resource targets
This will make CMake rebuild resources if for instance the fonts are
updated.
2024-08-06 17:48:24 +12:00
Diomendius
ee60ef57a1 Generate Packaged/Houses dirs as dependencies
Uses add_custom_command() to add rules for generating these directories,
rather than creating them only when CMakeLists.txt runs. With this
change, you can manually delete Packaged from the build directory
without causing subsequent builds to fail.
2024-08-06 17:46:10 +12:00
Diomendius
2681ffc5c6 Update instructions in LINUX.txt 2024-08-06 16:03:16 +12:00
Diomendius
6a13e44dae Add Tools CMake build target
All the individual executables are marked EXCLUDE_FROM_ALL, but the
added Tools custom target is marked ALL. The only visible effect of this
is that ConvertColorCursors does not get built by default, since all the
other tools are dependencies for the Resources or Tools targets, which
are both built by default. Otherwise, the benefit is simply to keep the
dependency tree clean. Only three targets are built by default:
Aerofoil, its resources and the conversion tools. Everything else is
built to satisfy dependencies.
2024-08-06 16:03:16 +12:00
Diomendius
68db3cd83e Add Executable build target
This is meant as an alias to the name of the main executable, for
consistency with the Executable install component.
2024-08-06 16:03:16 +12:00
Diomendius
13f0874757 Enable CMake Release build type and LTO by default 2024-08-06 16:03:16 +12:00
Diomendius
660d79980a Add add_data_file() to CMakeLists.txt
This automatically cleans up artifacts specified as BYPRODUCTS after
running the commands.
2024-08-06 16:03:16 +12:00
Diomendius
f65d550300 Add houses to CMake 2024-08-06 16:03:16 +12:00
Diomendius
d9049f3c8a Add icons to CMake (commented-out)
These are only used on Windows and the converted files have been
committed to the repo, but this might be useful to someone.
2024-08-06 16:03:16 +12:00
Diomendius
8a5b50d98d Add Fonts.gpf to CMake 2024-08-06 16:03:13 +12:00
Diomendius
91e2f3b25f Add ApplicationResources.gpf to CMake 2024-08-06 01:34:53 +12:00
Diomendius
0ebdabc12f Add ConvertColorCursors to CMake, port to *nix
- Includes WindowsUnicodeToolShim.h.
- Replaces sprintf_s() with std::ostringstream.
- Replaces fopen_s() with fopen_utf8().
- Switches to the toolMain() wrapper, which is a no-op on except on
  Windows, where it should improve Unicode support, though I can't test
  that on my end.
- Replaces \ with / in paths, which should still be Windows-compatible.
2024-08-06 01:34:53 +12:00
Diomendius
8b916867d5 Add GenerateFonts to CMake, port to *nix
Removes unused Windows-specific headers and adds arguments to specify
source and output directories, which is necessary for out-of-tree
builds, which are necessary to avoid name collisions on platforms where
executables have no file extension (so, basically everything except
Windows).
2024-08-06 01:34:53 +12:00
Diomendius
a7f5b653fa Add GpFontHandler_FreeType2 to CMake
Also add stddef.h include to GpRenderedGlyphMetrics.h to make size_t
visible. Does MSVC provide size_t by default, or via stdint.h? This
prevents compilation and I can't see how this would have compiled on
Windows otherwise.
2024-08-06 01:34:53 +12:00
Diomendius
5c74c96771 Add unpacktool to CMake, port to *nix
- Adds missing includes, removes some unused ones.
- Removes unused Windows.h and shellapi.h includes.
- Uses / as path separator. This is portable and should still work fine
  on Windows.
2024-08-06 01:28:44 +12:00
Diomendius
e78d93437a Add HouseTool to CMake 2024-08-06 00:50:29 +12:00
Diomendius
c2753ec679 Add MiniRez to CMake
Also includes <algorithm> to provide std::find(). Evidently something in
Windows implicitly provides find(), but it was broken on Linux.
2024-08-06 00:50:09 +12:00
Diomendius
f27860776b Add MergeGPF to CMake 2024-08-06 00:32:23 +12:00
Diomendius
77fcc35726 Add FTagData to CMake, port to *nix 2024-08-06 00:32:23 +12:00
Diomendius
e2bb19709d Add MakeTimestamp to CMake, port to *nix 2024-08-06 00:32:22 +12:00
Diomendius
8b2db1b142 Fix equality test in gpr2gpa.cpp
I don't think this actually gets hit when converting the base Glider PRO
resources, but it's an obvious error that makes the condition always
true.
2024-08-06 00:32:22 +12:00
Diomendius
77009b08ca Avoid Clang c++11-narrowing error
Downgrades c++11-narrowing to a warning when compiling with Clang. A
better solution would be to fix the error, but this at least brings
Clang in line with the more permissive GCC, which treats this as a
warning by default.
2024-08-06 00:32:10 +12:00
Diomendius
7a81b2b396 Add gpr2gpa to CMake, port to *nix 2024-08-06 00:16:22 +12:00
Diomendius
e2da9bb7c5 Add hqx2gp to CMake 2024-08-06 00:16:22 +12:00
Diomendius
796b2880cf Add hqx2bin to CMake 2024-08-06 00:16:22 +12:00
Diomendius
c372fcb92d Add bin2gp to CMake 2024-08-06 00:16:22 +12:00
Diomendius
1e4ee9335e Add flattenmov to CMake 2024-08-06 00:16:22 +12:00
Diomendius
e2fcd7851d Add UnixUnicodeToolShim.cpp
This is the counterpart to WindowsUnicodeToolShim.cpp for *nix systems.
2024-08-06 00:16:22 +12:00
Diomendius
9aa82066f1 Refactor CMakeLists.txt
The BUILD_INTERFACE generator expression isn't actually useful as we
don't use export(). CMAKE_CURRENT_SOURCE_DIR is also unnecessary as
CMake treats relative paths as relative to the current source directory
(or the current binary directory for outputs).
2024-08-04 12:57:13 +12:00
Diomendius
de3fdeb7b1 Fix double-use of va_list in AppendFmt
AppendFmt calls vsnprintf twice, first to check the size of the
formatted string, then to write it for real, but it used the same
va_list for both calls, so the second call got an invalid va_list after
the first call had already consumed all its arguments.

This is UB and at least on Linux makes the second call print garbage. I
presume Windows implements va_list differently such that this somehow
worked correctly, because on Linux, all of the dialog items get parsed
into invalid JSON due to this bug, with lines like this (note the
missing second array element and closing bracket):
    "pos" : [ -55947262,
2024-08-04 12:57:13 +12:00
elasota
0e1af575ca Fix missing return in error case 2024-08-03 15:51:46 -04:00
Eric Lasota
7a7cc8b0dc Merge pull request #20 from Diomendius/normalize_line_endings
Normalize line endings
2024-08-03 11:38:20 -04:00
19 changed files with 226 additions and 309 deletions

View File

@@ -343,13 +343,17 @@ target_include_directories(hqx2bin PRIVATE
)
target_link_libraries(hqx2bin PortabilityLayer)
add_executable(hqx2gp EXCLUDE_FROM_ALL hqx2gp/hqx2gp.cpp AerofoilPortable/GpAllocator_C.cpp)
add_executable(hqx2gp EXCLUDE_FROM_ALL
hqx2gp/hqx2gp.cpp
AerofoilPortable/GpAllocator_C.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(hqx2gp PRIVATE
Common
GpCommon
PortabilityLayer
AerofoilPortable
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(hqx2gp PortabilityLayer)
@@ -357,7 +361,7 @@ add_executable(gpr2gpa EXCLUDE_FROM_ALL
gpr2gpa/gpr2gpa.cpp
gpr2gpa/macedec.cpp
AerofoilPortable/GpAllocator_C.cpp
UnixCompat/UnixCompat.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(gpr2gpa PRIVATE
Common
@@ -365,52 +369,62 @@ target_include_directories(gpr2gpa PRIVATE
PortabilityLayer
AerofoilPortable
MacRomanConversion
UnixCompat
WindowsUnicodeToolShim
rapidjson/include
zlib
)
target_link_libraries(gpr2gpa PortabilityLayer MacRomanConversion zlib)
add_executable(MakeTimestamp EXCLUDE_FROM_ALL MakeTimestamp/MakeTimestamp.cpp)
target_include_directories(MakeTimestamp PRIVATE PortabilityLayer UnixCompat)
target_include_directories(MakeTimestamp PRIVATE PortabilityLayer)
target_link_libraries(MakeTimestamp PortabilityLayer)
add_executable(FTagData EXCLUDE_FROM_ALL FTagData/FTagData.cpp)
add_executable(FTagData EXCLUDE_FROM_ALL
FTagData/FTagData.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(FTagData PRIVATE
Common
GpCommon
PortabilityLayer
AerofoilPortable
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(FTagData PortabilityLayer)
add_executable(MergeGPF EXCLUDE_FROM_ALL MergeGPF/MergeGPF.cpp AerofoilPortable/GpAllocator_C.cpp)
add_executable(MergeGPF EXCLUDE_FROM_ALL
MergeGPF/MergeGPF.cpp
AerofoilPortable/GpAllocator_C.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(MergeGPF PRIVATE
Common
GpCommon
PortabilityLayer
AerofoilPortable
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(MergeGPF PortabilityLayer)
add_executable(MiniRez EXCLUDE_FROM_ALL MiniRez/MiniRez.cpp)
add_executable(MiniRez EXCLUDE_FROM_ALL MiniRez/MiniRez.cpp WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp)
target_include_directories(MiniRez PRIVATE
Common
GpCommon
PortabilityLayer
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(MiniRez PortabilityLayer)
add_executable(HouseTool EXCLUDE_FROM_ALL HouseTool/HouseTool.cpp)
add_executable(HouseTool EXCLUDE_FROM_ALL
HouseTool/HouseTool.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(HouseTool PRIVATE
Common
GpCommon
PortabilityLayer
MacRomanConversion
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(HouseTool PortabilityLayer MacRomanConversion)
@@ -438,13 +452,14 @@ add_executable(unpacktool EXCLUDE_FROM_ALL
unpacktool/StuffItHuffmanDecompressor.cpp
unpacktool/StuffItParser.cpp
unpacktool/unpacktool.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(unpacktool PRIVATE
Common
GpCommon
PortabilityLayer
MacRomanConversion
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(unpacktool PortabilityLayer MacRomanConversion)
@@ -464,13 +479,17 @@ if(FREETYPE_FOUND)
target_link_libraries(GpFontHandler_FreeType2 PRIVATE Freetype::Freetype)
add_executable(GenerateFonts EXCLUDE_FROM_ALL GenerateFonts/GenerateFonts.cpp AerofoilPortable/GpAllocator_C.cpp)
add_executable(GenerateFonts EXCLUDE_FROM_ALL
GenerateFonts/GenerateFonts.cpp
AerofoilPortable/GpAllocator_C.cpp
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(GenerateFonts PRIVATE
Common
GpCommon
PortabilityLayer
AerofoilPortable
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(GenerateFonts PortabilityLayer GpFontHandler_FreeType2)
endif()
@@ -479,6 +498,7 @@ add_executable(ConvertColorCursors EXCLUDE_FROM_ALL
ConvertColorCursors/ConvertColorCursors.cpp
AerofoilPortable/GpAllocator_C.cpp
stb/stb_image_write.c
WindowsUnicodeToolShim/UnixUnicodeToolShim.cpp
)
target_include_directories(ConvertColorCursors PRIVATE
Common
@@ -486,12 +506,16 @@ target_include_directories(ConvertColorCursors PRIVATE
PortabilityLayer
AerofoilPortable
stb
UnixCompat
WindowsUnicodeToolShim
)
target_link_libraries(ConvertColorCursors PortabilityLayer)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Packaged/Houses")
add_custom_target(BuildDirs
BYPRODUCTS Packaged tmp
COMMAND "${CMAKE_COMMAND}" -E make_directory Packaged/Houses tmp
VERBATIM
)
set(DATA_FILES)
@@ -499,87 +523,61 @@ function(add_data_file NAME)
list(APPEND DATA_FILES "Packaged/${NAME}")
set(DATA_FILES "${DATA_FILES}" PARENT_SCOPE)
cmake_parse_arguments(PARSE_ARGV 1 ARG
""
""
"BYPRODUCTS;COMMANDS"
cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "")
set(TMPDIR "${CMAKE_CURRENT_BINARY_DIR}/tmp/${NAME}")
list(TRANSFORM ARG_UNPARSED_ARGUMENTS
REPLACE {TMPDIR} "${TMPDIR}"
)
if(ARG_BYPRODUCTS)
set(RM_BYPRODUCTS_COMMAND COMMAND "${CMAKE_COMMAND}" -E rm)
set(RM_BYPRODUCTS_PATHS "${ARG_BYPRODUCTS}")
list(TRANSFORM RM_BYPRODUCTS_PATHS PREPEND "${CMAKE_CURRENT_BINARY_DIR}/")
endif()
add_custom_command(
OUTPUT "Packaged/${NAME}"
BYPRODUCTS ${ARG_BYPRODUCTS}
${ARG_COMMANDS}
${RM_BYPRODUCTS_COMMAND} ${RM_BYPRODUCTS_PATHS}
DEPENDS BuildDirs
COMMAND "${CMAKE_COMMAND}" -E make_directory "${TMPDIR}"
${ARG_UNPARSED_ARGUMENTS}
COMMAND "${CMAKE_COMMAND}" -E rename
"${TMPDIR}/${NAME}"
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/${NAME}"
COMMAND "${CMAKE_COMMAND}" -E rm -r -- "${TMPDIR}"
VERBATIM
)
endfunction()
add_data_file(ApplicationResources.gpf
BYPRODUCTS
Packaged/ApplicationResources.gpr
Packaged/ApplicationResources.gpa
COMMANDS
DEPENDS MiniRez gpr2gpa FTagData MergeGPF
DEPENDS
MiniRez gpr2gpa FTagData MergeGPF "GliderProData/Glider PRO.r"
ApplicationResourcePatches/manifest.json DefaultTimestamp.timestamp
COMMAND MiniRez
"GliderProData/Glider PRO.r"
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/ApplicationResources.gpr"
"{TMPDIR}/ApplicationResources.gpr"
COMMAND gpr2gpa
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/ApplicationResources.gpr"
"{TMPDIR}/ApplicationResources.gpr"
DefaultTimestamp.timestamp
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/ApplicationResources.gpa"
"{TMPDIR}/ApplicationResources.gpa"
-patch ApplicationResourcePatches/manifest.json
COMMAND FTagData
DefaultTimestamp.timestamp
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/ApplicationResources.gpf"
"{TMPDIR}/ApplicationResources.gpf"
data ozm5 0 0 locked
COMMAND MergeGPF
"${CMAKE_CURRENT_BINARY_DIR}/Packaged/ApplicationResources.gpf"
"{TMPDIR}/ApplicationResources.gpf"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
file(GLOB_RECURSE FONT_DEPS RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS Resources/Fonts/*)
add_data_file(Fonts.gpf
BYPRODUCTS
Packaged/Fonts.gpr
Packaged/Fonts.gpa
Packaged/FontCacheCatalog.bin
Packaged/FontCacheManifest.json
Packaged/CachedFont0.bin
Packaged/CachedFont1.bin
Packaged/CachedFont2.bin
Packaged/CachedFont3.bin
Packaged/CachedFont4.bin
Packaged/CachedFont5.bin
Packaged/CachedFont6.bin
Packaged/CachedFont7.bin
Packaged/CachedFont8.bin
Packaged/CachedFont9.bin
Packaged/CachedFont10.bin
Packaged/CachedFont11.bin
Packaged/CachedFont12.bin
Packaged/CachedFont13.bin
Packaged/CachedFont14.bin
COMMANDS
DEPENDS GenerateFonts MiniRez gpr2gpa FTagData MergeGPF
COMMAND GenerateFonts
"${CMAKE_SOURCE_DIR}/Resources"
Packaged
COMMAND MiniRez "${CMAKE_SOURCE_DIR}/Empty.r" Packaged/Fonts.gpr
DEPENDS GenerateFonts MiniRez gpr2gpa FTagData MergeGPF ${FONT_DEPS}
COMMAND GenerateFonts "${CMAKE_SOURCE_DIR}/Resources" {TMPDIR}
COMMAND MiniRez "${CMAKE_SOURCE_DIR}/Empty.r" {TMPDIR}/Fonts.gpr
COMMAND gpr2gpa
Packaged/Fonts.gpr
{TMPDIR}/Fonts.gpr
"${CMAKE_SOURCE_DIR}/DefaultTimestamp.timestamp"
Packaged/Fonts.gpa
-patch Packaged/FontCacheManifest.json
{TMPDIR}/Fonts.gpa
-patch {TMPDIR}/FontCacheManifest.json
COMMAND FTagData
DefaultTimestamp.timestamp
Packaged/Fonts.gpf
{TMPDIR}/Fonts.gpf
data ozm5 0 0 locked
COMMAND MergeGPF Packaged/Fonts.gpf
COMMAND MergeGPF {TMPDIR}/Fonts.gpf
)
# These files are committed to the repo and aren't currently useful on non-Windows systems anyway.
@@ -600,8 +598,10 @@ add_data_file(Fonts.gpf
#
#add_custom_command(
# OUTPUT ${CONVERTED_ICONS}
# DEPENDS ConvertColorCursors Packaged/ApplicationResources.gpr
# COMMAND ConvertColorCursors
# )
#add_custom_target(Icons DEPENDS ${CONVERTED_ICONS})
set(HOUSE_FILES)
@@ -620,20 +620,22 @@ function(add_house NAME)
list(APPEND HOUSE_FILES "${BASE_PATH}.gpf")
set(BYPRODUCTS "${BASE_PATH}.gpr" "${BASE_PATH}.gpa" "${BASE_PATH}.gpd")
set(BINHEX_SRC "${CMAKE_SOURCE_DIR}/GliderProData/Houses/${NAME}.binhex")
set(TS "${CMAKE_SOURCE_DIR}/DefaultTimestamp.timestamp")
add_custom_command(
OUTPUT
"${BASE_PATH}.gpf"
BYPRODUCTS
${BYPRODUCTS}
DEPENDS hqx2gp gpr2gpa MergeGPF
DEPENDS hqx2gp gpr2gpa MergeGPF BuildDirs "${BINHEX_SRC}" "${TS}"
COMMAND hqx2gp
"${CMAKE_SOURCE_DIR}/GliderProData/Houses/${NAME}.binhex"
"${CMAKE_SOURCE_DIR}/DefaultTimestamp.timestamp"
"${BINHEX_SRC}"
"${TS}"
"${BASE_PATH}"
COMMAND gpr2gpa
"${BASE_PATH}.gpr"
"${CMAKE_SOURCE_DIR}/DefaultTimestamp.timestamp"
"${TS}"
"${BASE_PATH}.gpa"
${PATCH_ARGS}
${HOUSE_EXTRA_COMMANDS}
@@ -644,7 +646,8 @@ function(add_house NAME)
VERBATIM
)
if(EXISTS "${CMAKE_SOURCE_DIR}/GliderProData/ConvertedMovies/${NAME}.mov.gpa")
set(MOV_GPA_SRC "${CMAKE_SOURCE_DIR}/GliderProData/ConvertedMovies/${NAME}.mov.gpa")
if(EXISTS "${MOV_GPA_SRC}")
list(APPEND HOUSE_FILES "${BASE_PATH}.mov.gpf")
add_custom_command(
@@ -652,13 +655,14 @@ function(add_house NAME)
"${BASE_PATH}.mov.gpf"
BYPRODUCTS
"${BASE_PATH}.mov.gpa"
DEPENDS FTagData MergeGPF BuildDirs "${MOV_GPA_SRC}" "${TS}"
COMMAND FTagData
"${CMAKE_SOURCE_DIR}/DefaultTimestamp.timestamp"
"${TS}"
"${BASE_PATH}.mov.gpf"
MooV ozm5 0 0 locked
COMMAND "${CMAKE_COMMAND}" -E copy
-t "Packaged/Houses"
"${CMAKE_SOURCE_DIR}/GliderProData/ConvertedMovies/${NAME}.mov.gpa"
"${MOV_GPA_SRC}"
COMMAND MergeGPF
"${BASE_PATH}.mov.gpf"
COMMAND "${CMAKE_COMMAND}" -E rm

View File

@@ -8,12 +8,11 @@
#include "QDStandardPalette.h"
#include "PLBigEndian.h"
#include "PLDrivers.h"
#include <assert.h>
#ifndef _WIN32
#include "UnixCompat.h"
#endif
#include "WindowsUnicodeToolShim.h"
#include <cassert>
#include <cstdio>
#include <sstream>
#include <string>
#include <vector>
@@ -96,12 +95,12 @@ void ConvertIconFamily(PortabilityLayer::ResourceFile *resFile, int32_t iconBitm
item.a = 0;
}
char outPath[256];
sprintf_s(outPath, "Aerofoil/ConvertedResources/%s%i.ico", prefix, resID);
std::string outPath = (
std::ostringstream() << "Aerofoil/ConvertedResources/" << prefix << resID << ".ico"
).str();
FILE *outF = nullptr;
errno_t outErr = fopen_s(&outF, outPath, "wb");
if (!outErr)
FILE *outF = fopen_utf8(outPath.c_str(), "wb");
if (outF)
{
IconDir iconDir;
iconDir.m_reserved = 0;
@@ -131,6 +130,8 @@ void ConvertIconFamily(PortabilityLayer::ResourceFile *resFile, int32_t iconBitm
fwrite(&iconDirEntry, 1, sizeof(IconDirEntry), outF);
fclose(outF);
}
else
perror(outPath.c_str());
delete[] pixelData;
bwBlock.Dispose();
@@ -138,12 +139,14 @@ void ConvertIconFamily(PortabilityLayer::ResourceFile *resFile, int32_t iconBitm
}
}
int main(int argc, const char **argv)
int toolMain(int argc, const char **argv)
{
FILE *f = nullptr;
errno_t err = fopen_s(&f, "Packaged/ApplicationResources.gpr", "rb");
if (err)
return err;
FILE *f = fopen_utf8("Packaged/ApplicationResources.gpr", "rb");
if (!f)
{
perror("Cannot open Packaged/ApplicationResources.gpr");
return -1;
}
PortabilityLayer::CFileStream stream(f);

View File

@@ -5,13 +5,7 @@
#include "CFileStream.h"
#include "CombinedTimestamp.h"
#ifdef _WIN32
#include <Windows.h>
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
int toolMain(int argc, const char **argv)
{

View File

@@ -17,13 +17,7 @@
#include "RenderedFont.h"
#include "RenderedFontCatalog.h"
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#include "GpFileSystem_Win32.h"
#include "GpSystemServices_Win32.h"
#else
#include "UnixCompat.h"
#endif
extern "C"
#ifdef _MSC_VER

View File

@@ -3,15 +3,10 @@
#include "PLBigEndian.h"
#include "MacRomanConversion.h"
#include "GpUnicode.h"
#include "WindowsUnicodeToolShim.h"
#include <vector>
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
typedef uint8_t Boolean;
#define kMaxScores 10

View File

@@ -1,16 +1,13 @@
#ifdef _WIN32
#include <Windows.h>
#include <stdint.h>
#include <cstdint>
#else
#include <string.h>
#include <time.h>
#include "UnixCompat.h"
#include <cstring>
#include <ctime>
#endif
#include <stdio.h>
#include <cstdio>
#include "CombinedTimestamp.h"
@@ -77,7 +74,7 @@ int main(int argc, const char **argv)
ts.SetMacEpochTime(currentTimeUnix + ts.kMacEpochToUTC);
ts.SetLocalYear(currentTimeStruct->tm_year + 1900);
ts.m_localMonth = currentTimeStruct->tm_mon;
ts.m_localMonth = currentTimeStruct->tm_mon + 1;
ts.m_localDay = currentTimeStruct->tm_mday;
ts.m_localHour = currentTimeStruct->tm_hour;
@@ -87,10 +84,10 @@ int main(int argc, const char **argv)
memset(ts.m_padding, 0, sizeof(ts.m_padding));
FILE *f;
if (fopen_s(&f, argv[1], "wb"))
FILE *f = fopen(argv[1], "wb");
if (!f)
{
fprintf(stderr, "Error opening output file");
perror("Error opening output file");
return -1;
}

View File

@@ -1,8 +1,4 @@
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
#include "CFileStream.h"
#include "CombinedTimestamp.h"

View File

@@ -10,12 +10,7 @@
#include "MacBinary2.h"
#include "MacFileMem.h"
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
// Very simplified resource compiler

View File

@@ -1,58 +0,0 @@
#include <cstring>
#include <string>
#include <vector>
#include <dirent.h>
void ScanDirectoryForExtension
(
std::vector<std::string> &outPaths,
const char *path,
const char *ending,
bool recursive
) {
DIR *dir = opendir(path);
if (!dir)
{
return;
}
size_t endingLen = strlen(ending);
dirent *ent;
while ((ent = readdir(dir)))
{
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
else if (recursive && ent->d_type == DT_DIR)
{
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
ScanDirectoryForExtension(
outPaths,
tmpPath.c_str(),
ending,
recursive
);
}
else
{
size_t nameLen = strlen(ent->d_name);
if (endingLen <= nameLen && memcmp
(
ent->d_name + nameLen - endingLen,
ending,
endingLen
) == 0
) {
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
outPaths.push_back(std::move(tmpPath));
}
}
}
closedir(dir);
}

View File

@@ -1,13 +1,12 @@
#pragma once
// This header provides POSIX-compatible versions of some functions from
// WindowsUnicodeToolShim and the Windows API.
#include "WindowsUnicodeToolShim.h"
#include <cstdio>
#include <cstdarg>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <dirent.h>
#include <sys/stat.h>
// Linux and macOS (and probably other non-Windows systems in general) do not
@@ -31,63 +30,18 @@
// though on the major non-Windows systems, assuming UTF-8 encoding is
// reasonable. For now, this header simply maps the WindowsUnicodeToolShim
// functions to their regular C API counterparts.
#define toolMain main
#define fopen_utf8 fopen
#define fputs_utf8 fputs
int toolMain(int argc, const char **argv);
int main(int argc, const char **argv) { return toolMain(argc, argv); }
typedef int errno_t;
FILE *fopen_utf8(const char *path, const char *options) { return fopen(path, options); }
int fputs_utf8(const char *str, FILE *f) { return fputs(str, f); }
int mkdir_utf8(const char *path) { return mkdir(path, 0777); }
inline int mkdir_utf8(const char *path)
void TerminateDirectoryPath(std::string &path)
{
return mkdir(path, 0777);
}
const size_t len = path.length();
// These use long as the offset type, which is 64 bits on 64-bit Linux and macOS
// systems, so explicitly 64-bit variants aren't necessary. 32-bit systems are
// likely to have a 32-bit long type, but we aren't likely to deal with
// multi-gigabyte files, are we?
#define _fseeki64 fseek
#define _ftelli64 ftell
// On Windows this is supposed to call an error handler if the buffer is too
// small. I don't think this is likely to happen in Aerofoil's case, but if it
// does, this function will crash the program as a precaution.
template <size_t size> int sprintf_s
(
char (&buffer)[size],
const char *format,
...
) {
va_list ap;
va_start(ap, format);
int count = vsnprintf(buffer, size, format, ap);
va_end(ap);
if (count >= size)
exit(1);
return count;
}
inline errno_t fopen_s(FILE **pFile, const char *name, const char *mode)
{
FILE *f = fopen(name, mode);
if (!f)
{
// Error codes might not match those from Windows, but all are
// non-zero, so *detecting* an error will work fine.
return errno;
}
*pFile = f;
return 0;
}
inline void TerminateDirectoryPath(std::string &path)
{
const size_t length = path.length();
if (length == 0 || path[length - 1] != '/')
if (len == 0 || path[len - 1] != '/')
path.push_back('/');
}
@@ -97,4 +51,49 @@ void ScanDirectoryForExtension
const char *path,
const char *ending,
bool recursive
);
) {
DIR *dir = opendir(path);
if (!dir)
{
return;
}
size_t endingLen = strlen(ending);
dirent *ent;
while ((ent = readdir(dir)))
{
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
else if (recursive && ent->d_type == DT_DIR)
{
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
ScanDirectoryForExtension(
outPaths,
tmpPath.c_str(),
ending,
recursive
);
}
else
{
size_t nameLen = strlen(ent->d_name);
if (endingLen <= nameLen && memcmp
(
ent->d_name + nameLen - endingLen,
ending,
endingLen
) == 0
) {
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
outPaths.push_back(std::move(tmpPath));
}
}
}
closedir(dir);
}

View File

@@ -8,6 +8,7 @@ int mkdir_utf8(const char *path);
void TerminateDirectoryPath(std::string &path);
void ScanDirectoryForExtension(std::vector<std::string>& outPaths, const char *path, const char *ending, bool recursive);
#ifdef _WIN32
struct DirectoryScanContext;
struct DirectoryScanEntry
{
@@ -17,3 +18,11 @@ struct DirectoryScanEntry
DirectoryScanContext *opendir_utf8(const char *name);
DirectoryScanEntry *readdir_utf8(DirectoryScanContext *dir);
void closedir_utf8(DirectoryScanContext *context);
#else
inline int _fseeki64(FILE *stream, long offset, int whence) {
return fseek(stream, offset, whence);
}
inline long _ftelli64(FILE *stream) { return ftell(stream); };
#endif

View File

@@ -24,21 +24,17 @@
#include "rapidjson/rapidjson.h"
#include "rapidjson/document.h"
#include "WindowsUnicodeToolShim.h"
#include "macedec.h"
#include <stdio.h>
#include <string>
#include <sstream>
#include <utility>
#include <vector>
#include <algorithm>
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#include "GpWindows.h"
#else
#include "UnixCompat.h"
#endif
enum AudioCompressionCodecID
{
AudioCompressionCodecID_VariableRate = -2,
@@ -2436,14 +2432,11 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
const size_t numRefs = typeList.m_numRefs;
{
char subName[256];
sprintf_s(subName, "%s", resTag.m_id);
PlannedEntry entry;
entry.m_name = subName;
entry.m_name = resTag.m_id;
entry.m_isDirectory = true;
contents.push_back(entry);
contents.push_back(std::move(entry));
}
for (size_t rlIndex = 0; rlIndex < numRefs; rlIndex++)
@@ -2462,14 +2455,15 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
if (typeList.m_resType == pictTypeID || typeList.m_resType == dateTypeID)
{
char resName[256];
sprintf_s(resName, "%s/%i.bmp", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".bmp"
).str();
if (ContainsName(reservedNames, resName))
if (ContainsName(reservedNames, resName.c_str()))
continue;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
if (ImportPICT(entry.m_uncompressedContents, resData, resSize, dumpqtDir, res.m_resID))
@@ -2479,14 +2473,15 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
}
else if (typeList.m_resType == sndTypeID)
{
char resName[256];
sprintf_s(resName, "%s/%i.wav", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".wav"
).str();
if (ContainsName(reservedNames, resName))
if (ContainsName(reservedNames, resName.c_str()))
continue;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
if (ImportSound(entry.m_uncompressedContents, resData, resSize, res.m_resID))
@@ -2496,14 +2491,15 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
}
else if (typeList.m_resType == indexStringTypeID)
{
char resName[256];
sprintf_s(resName, "%s/%i.txt", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".txt"
).str();
if (ContainsName(reservedNames, resName))
if (ContainsName(reservedNames, resName.c_str()))
continue;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
if (ImportIndexedString(entry.m_uncompressedContents, resData, resSize))
@@ -2511,14 +2507,15 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
}
else if (typeList.m_resType == ditlTypeID)
{
char resName[256];
sprintf_s(resName, "%s/%i.json", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".json"
).str();
if (ContainsName(reservedNames, resName))
if (ContainsName(reservedNames, resName.c_str()))
continue;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
if (ImportDialogItemTemplate(entry.m_uncompressedContents, resData, resSize))
@@ -2533,15 +2530,16 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
const IconTypeSpec &iconSpec = iconTypeSpecs[i];
if (typeList.m_resType == iconSpec.m_resTypeID)
{
char resName[256];
sprintf_s(resName, "%s/%i.bmp", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".bmp"
).str();
if (!ContainsName(reservedNames, resName))
if (!ContainsName(reservedNames, resName.c_str()))
{
isIcon = true;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
if (ImportIcon(entry.m_uncompressedContents, resData, resSize, iconSpec.m_width, iconSpec.m_height, iconSpec.m_bpp))
@@ -2554,15 +2552,16 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
if (!isIcon)
{
char resName[256];
sprintf_s(resName, "%s/%i.bin", resTag.m_id, static_cast<int>(res.m_resID));
std::string resName = (
std::ostringstream() << resTag.m_id << '/' << res.m_resID << ".bin"
).str();
if (ContainsName(reservedNames, resName))
if (ContainsName(reservedNames, resName.c_str()))
continue;
PlannedEntry entry;
entry.m_name = resName;
entry.m_name = std::move(resName);
entry.m_comment = resComment;
entry.m_uncompressedContents.resize(res.GetSize());
@@ -2609,6 +2608,7 @@ int ConvertDirectory(const std::string &basePath, const PortabilityLayer::Combin
fprintf(stderr, "Failed to open metadata file ");
fputs_utf8(metaPath.c_str(), stderr);
fprintf(stderr, "\n");
return -1;
}
PortabilityLayer::MacFilePropertiesSerialized mfps;

View File

@@ -31,12 +31,7 @@ SOFTWARE.
#include "MacBinary2.h"
#include "MacFileMem.h"
#include "ZipFile.h"
#ifdef _WIN32
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
#include <string>

View File

@@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <cstdint>
#include "IDecompressor.h"

View File

@@ -1,6 +1,6 @@
#pragma once
#include <stddef.h>
#include <cstddef>
struct CSInputBuffer;

View File

@@ -1,7 +1,7 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <cstddef>
#include <cstdint>
struct IFileReader
{

View File

@@ -1,4 +1,4 @@
#include <limits.h>
#include <climits>
#include "PrefixCode.h"

View File

@@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <cstdint>
#include "IDecompressor.h"

View File

@@ -1,17 +1,4 @@
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#ifdef _WIN32
#include <Windows.h>
#include <shellapi.h>
#include "WindowsUnicodeToolShim.h"
#else
#include "UnixCompat.h"
#endif
#include "IArchiveParser.h"
#include "IFileReader.h"
@@ -35,8 +22,15 @@
#include "CompactProLZHRLEDecompressor.h"
#include "CSInputBuffer.h"
#include "WindowsUnicodeToolShim.h"
#include "CombinedTimestamp.h"
#include <string.h>
#include <string>
#include <vector>
class CFileReader final : public IFileReader
{
public: