// The MIT License (MIT) // // Copyright (C) 2026 Scott Duensing // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // setupCore.h -- Setup's work without its window: the target folder, // the list of installed files, removing DVX, DVX.INI and AUTOEXEC.BAT // (host tested) // // SETUP.EXE unpacks the DVX package (pkgRead.h) into the target folder: // the program, and of the fonts none, the base set, or all (the package's // tiers, pkgFormat.h). // The package holds the program only (the DVX folder layout: dvxPlat.h); // everything written while DVX runs is in the user folder (USER, or the // folder DVXUSER names), which the package never holds and an upgrade // never touches, so the user's settings, groups, and files survive. On a // folder that already holds DVX (its SETUP.LST) Setup asks whether to // keep them or start them over (the user folder removed). Every file the // package put there is listed in SETUP.LST in the folder; Uninstall // removes those files (and the user folder when asked), then the folders // left empty. A new install (or one whose settings start over) gets the // user's DVX.INI: the shipped SYSTEM\DVX.INI with the display mode Setup // ran in (known to work on this computer). #ifndef SETUP_CORE_H #define SETUP_CORE_H #include "pkgFormat.h" #include "dvxPlat.h" #include #include // The program AUTOEXEC.BAT starts, in the target folder #define SETUP_EXE_NAME "DVX.EXE" // AUTOEXEC.BAT in the root of the boot drive, and the copy of it Setup // keeps before changing it (AUTOEXEC.DVX) #define SETUP_AUTOEXEC_NAME "AUTOEXEC.BAT" #define SETUP_AUTOEXEC_BAK ".DVX" // The list of installed files, in the DVX folder (one relative name with // '/' per line) #define SETUP_LIST_NAME "SETUP.LST" // What Setup installs of the fonts: the last of the package's tiers it // unpacks (tier 0 the program, 1 the base set of fonts, 2 the others) typedef enum { SetupFontsNoneE, SetupFontsBaseE, SetupFontsAllE, SetupFontsCountE } SetupFontsE; _Static_assert(SetupFontsCountE == PKG_TIERS, "a fonts choice per package tier"); // The fonts folder as SETUP.LST names it (an upgrade with fewer fonts // removes the ones it leaves out: setupRemoveDropped) #define SETUP_FONTS_FOLDER DVX_SHARED_DIR "/" DVX_FONTS_DIR "/" // Room a file takes beyond its size on the target disk (half a 16 KB // cluster, typical of a FAT16 hard disk), for the free space check #define SETUP_FILE_SLACK 8192 // Longest message the functions below return #define SETUP_ERR_MAX 320 // Add line (with a CR LF) to the end of the batch file at path, after // copying it to its SETUP_AUTOEXEC_BAK sibling. A missing file is // created (nothing to back up). The change is written to a scratch file // and swapped in, so a failure leaves the file as it was. False with a // reason in err. bool setupAutoexecAdd(const char *path, const char *line, char *err, int32_t errSize); // True when the batch file at path already has line (blanks around it and // case ignored). bool setupAutoexecHasLine(const char *path, const char *line); // The AUTOEXEC.BAT line that starts DVX from destDir: destDir\DVX.EXE by // destDir's short path (AUTOEXEC.BAT runs before a long-name driver; the // loader changes to its own folder first). Setup starts DVX by it too. // False when it does not fit. bool setupAutoexecLine(const char *destDir, char *out, int32_t outSize); // Path of AUTOEXEC.BAT on the boot drive ("C:\AUTOEXEC.BAT"). False when // there is no boot drive (0). bool setupAutoexecPath(char bootDrive, char *out, int32_t outSize); // Take every copy of line out of the batch file at path (backed up and // swapped in like setupAutoexecAdd). True when there was nothing to // remove; false with a reason in err. bool setupAutoexecRemove(const char *path, const char *line, char *err, int32_t errSize); // Check a target folder: given, a full path, and neither the folder the // package is read from nor inside it. False with a reason in err. bool setupCheckDest(const char *srcDir, const char *destDir, char *err, int32_t errSize); // What of the fonts the DVX in destDir has, judged from its SETUP.LST and // info's tiers: none, at most the base set's files, or more. A folder // without a list (a new install) gets all of them. SetupFontsE setupFontsInstalled(const char *destDir, const PkgHeaderT *info); // True when the DVX in destDir has the user's DVX.INI (platformUserDirOf). bool setupHasSettings(const char *destDir); // True when destDir already holds a DVX: its DVX.EXE (installed, copied // there, or run from there) or SETUP.LST (an install partly removed). bool setupIsInstalled(const char *destDir); // Remove the user folder of the DVX in destDir (platformUserDirOf), its // settings and files, when it holds a DVX.INI (a folder that does not is // left alone, whatever DVXUSER names). False only when removing failed. bool setupRemoveUser(const char *destDir); // Write destDir's SETUP.LST: the names in files (relative, '/') plus // those of the old list whose files are still there. False when it // cannot be written. bool setupListWrite(const char *destDir, char *const *files, int32_t count); // Remove the files under folder (a name ending in '/', as SETUP.LST has // it) that destDir's list has and files (the new install's) does not -- // what an upgrade with fewer fonts leaves out -- then those of its // folders left empty. Call it before setupListWrite. void setupRemoveDropped(const char *destDir, const char *folder, char *const *files, int32_t count); // Remove what a cancelled new install wrote: the files, then the folders // it made (newest first) when they are empty. void setupRemoveWritten(char *const *written, int32_t writtenCount, char *const *dirs, int32_t dirCount); // Bytes tiers 0 .. tier of the package need on the target disk. uint64_t setupSpaceNeeded(const PkgHeaderT *info, SetupFontsE tier); // Remove DVX from destDir: every file in SETUP.LST, the user folder when // removeSettings (setupRemoveUser), the list itself, then every folder // left empty, destDir too. Files the user added stay. // False with a reason in err when the list is missing or a file could // not be removed (the rest is still removed). bool setupUninstall(const char *destDir, bool removeSettings, char *err, int32_t errSize); // Store the display mode in the user's DVX.INI of the DVX in destDir, // made from the shipped SYSTEM\DVX.INI when there is none yet. False // when it cannot be saved. bool setupWriteIni(const char *destDir, int32_t width, int32_t height, int32_t bpp); #endif // SETUP_CORE_H