Commit Graph

12661 Commits

Author SHA1 Message Date
David Korth
2934ccd46a [rpcli] vt.cpp, win32_console_print_ansi_color(): Convert the if/else block to switch/case.
Some checks failed
Codecov / run (push) Has been cancelled
gcc is able to optimize the if/else block into a jump table, but MSVC
gets confused and fails to optimize it. Converting to switch/case
allows both compilers to optimize it using a jump table.

The gcc version might be slightly bigger now due to explicitly stating
the 30-37 and 40-47 cases instead of checking ranges, but it might be
slightly faster due to not having to check ranges and instead simply
jumping to the correct case.
2025-04-24 01:53:04 -04:00
David Korth
4a1287da34 [rpcli] vt.cpp: Handle a few more attributes.
- 22: normal intensity
- 39: default foreground color
- 49: default background color
2025-04-24 01:51:14 -04:00
David Korth
141048d453 [rpcli] vt.cpp: Fix a typo that broke background color handling.
Should be checking for [40,47], not [40,37].
2025-04-24 01:51:14 -04:00
David Korth
f044ef5559 [rpcli] vt.cpp: Handle the Reset sequence and some more attributes.
\033[m with no number should be interpreted as 0 (Reset).

Also, simply ignore invalid (unsupported) attribute numbers instead
of stopping \033[m processing entirely. Otherwise, the 'm' might
end up getting printed.

Add support for the following attributes:
- 4 (underline)
- 7 (reverse video)
- 27 (not-reverse video)

NOTE: These work on Windows 10, but not Windows 7. The Windows 10 support
is redundant, since on Windows 10, we're normally sending ANSI escape
sequences directly to the console, instead of using the custom handler.

Maybe these attributes work on Windows 8 and/or 8.1?
2025-04-24 01:50:45 -04:00
David Korth
91d7fa8584 [rpcli] vt.cpp, ConsolePrintNewline(): Fix copy/paste error in the stdio fallback path. 2025-04-24 01:21:16 -04:00
David Korth
740da2d882 [rpcli] vt.hpp: Reduce ConsoleInfo_t size on Windows.
Move `uint16_t wAttributesOrig` before `HANDLE hConsole`. HANDLE is
64-bit aligned (on 64-bit), so it ends up leaving some space after
the bools that we can reuse for the uint16_t.

64-bit Windows:
Size before: 32 bytes
Size after:  24 bytes
Difference:  -8 bytes

32-bit Windows:
Size before: 16 bytes
Size after:  16 bytes
Difference:   0 bytes

Effectively no difference on 32-bit, but reduces it by 8 bytes on 64-bit.
2025-04-24 01:13:05 -04:00
David Korth
ca67d8c20d [rpcli] vt.cpp: On Windows 10, MinTTY (git bash, cygwin) acts like a real console.
WriteConsole() works, etc.

TODO: Verify Windows 7 behavior.
2025-04-24 01:10:35 -04:00
David Korth
aa6cbba46e [rpcli] vt.cpp: Constify ConsoleInfo_t* parameters. 2025-04-24 01:09:32 -04:00
David Korth
7990dd3364 [rpcli] vt.cpp: New function ConsolePrintNewline().
This prints a newline using WriteConsole() on Windows if possible.
Otherwise, it uses stdio.

Use ConsolePrintNewline() anywhere putchar('\n') or fputc('\n', stdxxx)
was used.

TODO: Optimize by not requiring a full utf8_to_utf16() here?
That might be a "super-micro-optimization", though...
2025-04-24 01:08:21 -04:00
David Korth
deb63624bc [rpcli] vt.cpp: Add an explicitly-counted version of ConsolePrint().
This eliminates an strlen() when using a C++ string.

There are now two inline wrappers:
- one for C strings with implicit length
- one for C++ strings with explicit length

Both of these wrappers call the real ConsolePrint, which takes an
explicit length and doesn't take any optional arguments.

Also, the C++ wrapper was returning the return value from a void
function, which somehow "worked", but isn't correct.

Use fwrite() instead of fputs() when the size is known.
2025-04-24 01:03:19 -04:00
David Korth
9a799984a9 [rpcli] rpcli.cpp: LibRpText::utf8_to_utf16() isn't used here.
I used it while doing some testing with WriteConsole(), but that
function is now called in vt.cpp, and not by rpcli.cpp directly.

Also removed `using std::u16string;`.
2025-04-23 00:10:11 -04:00
David Korth
0728d16649 [rpcli] rpcli.cpp: Check for libgnuintl-8.dll before romdata-6.dll.
romdata-6.dll also depends on libgnuintl-8.dll, so if libgnuintl-8.dll
is missing, romdata-6.dll won't be usable, either.

FIXME: libromdata doesn't appear to have a libgnuintl-8.dll check...
2025-04-23 00:05:35 -04:00
David Korth
73bc840583 [rpcli] vt.cpp, win32_write_to_console(): Use WriteConsoleA() if ANSI escape sequences are supported.
Support for ANSI escape sequences was added in Windows 10 1607, which
also handles UTF-8 console output correctly. Use WriteConsoleA() so
we don't have to convert from UTF-8 to UTF-16.
2025-04-22 22:12:35 -04:00
David Korth
953d80e483 [rpcli] rpcli.cpp, DoFile(): Use the non-ANSI version even on Windows 10 1607 and later.
WriteConsole() is faster than printf/cout on Windows.

TODO: Maybe use WriteConsoleA() instead, so we can take advantage of
ANSI escape and UTF-8 support while also getting the performance benefit
of WriteConsole().
2025-04-22 21:54:53 -04:00
David Korth
4a238c2f1e [rpcli] TODO: If using Win10 1607 with UTF-8, use WriteConsoleA()? 2025-04-22 21:39:38 -04:00
David Korth
166e773f3f [rpcli] verifykeys.cpp: Use ConsolePrint(). 2025-04-22 21:15:19 -04:00
David Korth
7273c8b658 [rpcli] rpcli.cpp, ShowUsage(): Forgot to remove a fputc('\n', stderr);.
This resulted in an extra newline when showing usage in builds that
support decryption.

This fixes a regression from commit aa6f1aba07.
([rpcli] rpcli.cpp: New function ConsolePrint(), now used by ShowUsage().)
2025-04-22 21:11:37 -04:00
David Korth
539bdcd2b3 [rpcli] vt.cpp, init_vt(): Initialize the ConsoleInfo_t streams on Linux, too.
Somehow missed this in commit a2a61e614163f1c5968421803130bb2d88b369b0...
([rpcli] Rework the various Windows console functions to take ConsoleInfo_t*.)
2025-04-22 21:10:04 -04:00
David Korth
6cb4cbb503 [rpcli] Move ConsolePrint() from rpcli.cpp to vt.cpp.
ConsolePrint() works on both Windows and Linux.

On Linux, it merely calls stdio functions.

On Windows, it calls stdio functions if not using a real console.
Otherwise, it uses WriteConsole().
2025-04-22 21:03:49 -04:00
David Korth
5cb7db18ea [rpcli] rpcli.cpp: Minor syntax error. (oops!) 2025-04-22 21:03:16 -04:00
David Korth
2cd5fc45f4 NEWS.md: Mention UTF-8 improvements in rpcli. 2025-04-22 21:00:41 -04:00
David Korth
3f285b2762 [rpcli] rpcli.cpp, _tmain(): Use ConsolePrint(). 2025-04-22 20:57:46 -04:00
David Korth
b1227d7699 [rpcli] rpcli.cpp, DoScsiInquiry() and DoAtaIdentifyDevice(): Use ConsolePrint() more. 2025-04-22 20:49:53 -04:00
David Korth
6a62448232 [rpcli] rpcli.cpp, DoAtaIdentifyDevice(): Missing packet parameter in the WriteConsole() path. 2025-04-22 20:48:47 -04:00
David Korth
ec7df32cda [rpcli] rpcli.cpp, PrintSystemRegion() and PrintPathnames(): Use ConsolePrint(). 2025-04-22 20:35:23 -04:00
David Korth
f8d6e76510 [rpcli] rpcli.cpp, ExtractImages() and DoFile(): Use ConsolePrint().
Add a ConsolePrint() overload that takes std::string.

NOTE: May be more efficient if the std::string overload calls
win32_write_to_console() with an actual length parameter, but
it takes more effort to maintain two versions of this function...
2025-04-22 20:31:16 -04:00
David Korth
d29169b35c [locale] es.po: Missing apostrophe in a string:
msgid "Extracting {0:s} into '{1:s}'"
msgstr "Extracción de {0:s} en '{1:s}'"
2025-04-22 20:26:40 -04:00
David Korth
a2a61e6141 [rpcli] Rework the various Windows console functions to take ConsoleInfo_t*.
Add FILE* and HANDLE (on Windows only) to ConsoleInfo_t.

vt.cpp: GetStdHandle() returns INVALID_HANDLE_VALUE on error,
so check for that.
2025-04-22 20:17:58 -04:00
David Korth
aa6f1aba07 [rpcli] rpcli.cpp: New function ConsolePrint(), now used by ShowUsage().
On Windows, ConsolePrint() uses win32_write_to_console() to print
Unicode text using WriteConsoleW() if a real console is in use.
2025-04-22 20:05:34 -04:00
David Korth
03d3400e27 [rpcli] rpcli.cpp: Use WriteConsole() for ATA and SCSI inquiries. 2025-04-22 19:52:31 -04:00
David Korth
8e48fd28f1 [rpcli] DoScsiInquiry(): Fix an inverted condition that broke SCSI inquiry.
It was showing an error if the file specified was in fact a device file,
which prevents it from working.

This fixes a regression from commit 837315505e.
([rpcli] rpcli.cpp: Un-indent a few functions.)

Affects: v2.3 - v2.5
2025-04-22 19:51:44 -04:00
David Korth
3bbe0f63c5 [rpcli] vt.cpp: Create a struct for the console properties and split it into stdout/stderr.
This will be useful when updating the stderr stuff in rpcli.cpp to use
WriteConsole() for both Unicode and performance reasons.

rpcli.cpp: Update for this change.
2025-04-22 19:37:32 -04:00
David Korth
bb5213ab60 [rpcli] vt.cpp: New variable is_real_console.
This is true if using a real Windows console, and false if using e.g.
MinTTY. MinTTY supports ANSI escape sequences, but not WriteConsole().

rpcli.cpp: Don't use WriteConsole() if we aren't using a real console.
2025-04-22 19:20:58 -04:00
David Korth
5a6309417c [rpcli] rpcli.cpp, DoFile(): Always use WriteConsole() for JSON.
This is faster than even using UTF-8 output on Windows 10 1607.

vt.cpp: win32_write_to_console(): Write in 4096-character chunks.
WriteConsole() seems to fail if the input buffer is > 64 KiB.

rpcli's JSON for rpcli.exe is 40,057 characters, which is > 64 KiB
with UTF-16 and failed to write. (The ANSI version "worked", though
without Unicode handling.)
2025-04-22 19:15:54 -04:00
David Korth
5833175378 [rpcli] Use WriteConsole() for text and JSON output.
WriteConsole() with Unicode (UTF-16) text seems to work around the
issue that was causing UTF-8 output to freeze on Windows 7. It's also
quite a bit faster than printf/cout on Windows.

WriteConsole() *does* work with ANSI escape sequences on Windows 10 1607,
so I'm going to do some reworking to make more use of it.

CMakeLists.txt: Remove the std::string_view check, since it's no longer
used in vt.cpp.
2025-04-22 18:58:21 -04:00
David Korth
8f23cc85d9 NEWS.md: Mention the Windows UTF-8 console output issues, and add a v2.5 entry for this. 2025-04-21 23:38:59 -04:00
David Korth
18d005bb2b FIXME: On Windows 7, UTF-8 console output can randomly crash the program.
Some checks failed
Codecov / run (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
Not sure why. It's probably a limitation of the older console.

It works on Windows 10. (tested on 1809)

TODO: Does it work on Windows 8 or 8.1?
2025-04-21 23:36:12 -04:00
David Korth
602165f822 [libi18n] gettext.h: Synchronize with the latest version from gnulib.
Updated in gnulib on 2025/01/01.
2025-04-21 23:27:55 -04:00
David Korth
684ef662a7 [gettext.win32] Updated to gettext-0.24.
Compiled with:
- i386:  gcc-14.2.1_p20241116, MinGW-w64 12.0.0
- amd64: gcc-14.2.1_p20241221, MinGW-w64 12.0.0

I tried updating it before, but every time I rebuilt gettext, it would
cause all of rom-properties to crash on startup. It turns out the
problem was -Wl,--pic-executable; removing this fixed it.

This *might* prevent ASLR .reloc sections from being generated in the
gettext executables. These are only used at compile time, so it's not
that big of an issue.

Removed most of the patches, since they are no longer necessary.
The remaining patches:

- 001-gettext-runtime-disable-iconv.patch
- 122-Use-LF-as-newline-in-envsubst.patch

Both patches have been updated for gettext-0.24.

TODO: Build for arm, arm64, and arm64ec.
2025-04-21 20:37:26 -04:00
David Korth
384c3d5abb [tracker] tracker-mini.c: Simplify the API version check a bit.
Check that the first .so file was opened before opening the second one.

Code size difference: (64-bit Gentoo Linux, gcc-14.2.1_p20250301, release build, no LTO)

   text    data     bss     dec     hex filename
   1798      96     160    2054     806 tracker-mini.c.o [before]
   1774      96     160    2030     7ee tracker-mini.c.o [after]
    -24       0       0     -24     -18 Difference
2025-04-21 20:31:40 -04:00
David Korth
9493b2c374 [tracker] tracker-mini.c: Use a loop to check for the various API versions.
Code size difference: (64-bit Gentoo Linux, gcc-14.2.1_p20250301, release build, no LTO)

   text    data     bss     dec     hex filename
   2198       0     160    2358     936 tracker-mini.c.o [before]
   1798      96     160    2054     806 tracker-mini.c.o [after]
   -400     +96       0    -304    -130 Difference
2025-04-21 20:29:38 -04:00
David Korth
a3f4a3861d [libromdata] EXEPrivate::addFields_PE(): Don't show the "XML parsing failed" warning if the EXE doesn't actually have a manifest. 2025-04-21 20:25:40 -04:00
David Korth
e1c90493e2 [tracker] tracker-mini.c: Forgot to call close_modules() after checking for LocalSearch 3.8. 2025-04-20 16:52:38 -04:00
David Korth
ee887913a6 [debian] rules: Set TRACKER_INSTALL_API_VERSION=AUTO.
Otherwise, I might forget to update it when building for various versions
of Ubuntu, which will result in Tracker being installed in the wrong
place for most newer versions.
2025-04-20 16:50:54 -04:00
David Korth
36da8b7168 NEWS.md: Mention localsearch support. 2025-04-20 16:32:50 -04:00
David Korth
3780a5b2e7 [tracker] Add support for localsearch-3.8, aka tracker-3.8.
Various pathnames were changed, but the API is essentially the same.

The API version will be handled as "3L".

dlopen-notes.h: Add ELF_NOTE_DLOPEN8().

[tracker] dlopen-notes.c: Add the API 3L library names.

NOTE: The Ubuntu 25.04 packages were all compiled with a hard-coded
-DTRACKER_INSTALL_API_VERSION=1. This should probably be removed from
debian/rules and we should just rely on auto-detection.

TODO: Release a v2.5.1 with this fix?
2025-04-20 16:30:04 -04:00
David Korth
d60312e3eb [tracker] 14-rp-rom-images.rule: Add "nfo:GameImage" as a fallback type.
tracker-3.8 (localsearch-3.8) has this in 15-games.rule.
2025-04-20 16:21:01 -04:00
David Korth
7513c2f45d [tracker] 14-rp-textures.rule: Add image/qoi and image/x-qoi.
Forgot to do this when adding support for Qoi images in v2.5.
2025-04-20 14:43:56 -04:00
David Korth
c5331ad0e4 [libromdata/tests] RomHeaderTest: Add KQ9E01 (Zelda 4SWORD) to the NintendoDS test.
This DSiWare SRL has an animated icon.
2025-04-20 14:17:27 -04:00
David Korth
cdfdf04d7e [libromdata] NintendoDS_BNR: Assume the icon isn't animated if frame 0 delay is 1 but frame 1 delay is 0.
Delay of 0 means "end of sequence". This effectively is the same as a
static icon, but the previous method of just checking frame 0's delay
didn't work.

This resulted in the following ROM headers as being detected as having
an animated icon when they didn't:
- DMFEA4
- DSYESZ
- VSOE8P

TODO: Add one that does.

nds_structs.h: Mark some enum constants as unsigned.

This fixes a regression from commit f5d34d97cb.
([libromdata] NintendoDS_BNR::imgpf(): Check for animated icons.)
2025-04-20 14:09:36 -04:00