1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[misc] improve/factorize '/' ↔ '\' conversions

This commit is contained in:
Pete Batard 2022-07-09 18:16:42 +01:00
parent 14f19e5275
commit 2b7b81808f
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
3 changed files with 21 additions and 27 deletions

View file

@ -328,15 +328,14 @@ static BOOL check_iso_props(const char* psz_dirname, int64_t file_length, const
static void fix_config(const char* psz_fullpath, const char* psz_path, const char* psz_basename, EXTRACT_PROPS* props) static void fix_config(const char* psz_fullpath, const char* psz_path, const char* psz_basename, EXTRACT_PROPS* props)
{ {
BOOL modified = FALSE; BOOL modified = FALSE;
size_t i, nul_pos; size_t nul_pos;
char *iso_label = NULL, *usb_label = NULL, *src, *dst; char *iso_label = NULL, *usb_label = NULL, *src, *dst;
nul_pos = safe_strlen(psz_fullpath);
src = safe_strdup(psz_fullpath); src = safe_strdup(psz_fullpath);
if (src == NULL) if (src == NULL)
return; return;
for (i=0; i<nul_pos; i++) nul_pos = strlen(src);
if (src[i] == '/') src[i] = '\\'; to_windows_path(src);
// Add persistence to the kernel options // Add persistence to the kernel options
if ((boot_type == BT_IMAGE) && HAS_PERSISTENCE(img_report) && persistence_size) { if ((boot_type == BT_IMAGE) && HAS_PERSISTENCE(img_report) && persistence_size) {
@ -437,25 +436,21 @@ static void fix_config(const char* psz_fullpath, const char* psz_path, const cha
static void print_extracted_file(char* psz_fullpath, uint64_t file_length) static void print_extracted_file(char* psz_fullpath, uint64_t file_length)
{ {
size_t i, nul_pos; size_t nul_pos;
if (psz_fullpath == NULL) if (psz_fullpath == NULL)
return; return;
// Replace slashes with backslashes and append the size to the path for UI display // Replace slashes with backslashes and append the size to the path for UI display
to_windows_path(psz_fullpath);
nul_pos = strlen(psz_fullpath); nul_pos = strlen(psz_fullpath);
for (i = 0; i < nul_pos; i++)
if (psz_fullpath[i] == '/')
psz_fullpath[i] = '\\';
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, TRUE, FALSE)); safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, TRUE, FALSE));
uprintf("Extracting: %s\n", psz_fullpath); uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, FALSE, FALSE)); safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, FALSE, FALSE));
PrintStatus(0, MSG_000, psz_fullpath); // MSG_000 is "%s" PrintStatus(0, MSG_000, psz_fullpath); // MSG_000 is "%s"
// ISO9660 cannot handle backslashes
for (i = 0; i < nul_pos; i++)
if (psz_fullpath[i] == '\\')
psz_fullpath[i] = '/';
// Remove the appended size for extraction // Remove the appended size for extraction
psz_fullpath[nul_pos] = 0; psz_fullpath[nul_pos] = 0;
// ISO9660 cannot handle backslashes
to_unix_path(psz_fullpath);
} }
static void alt_print_extracted_file(const char* psz_fullpath, uint64_t file_length) static void alt_print_extracted_file(const char* psz_fullpath, uint64_t file_length)
@ -1255,13 +1250,9 @@ out:
static_sprintf(path, "%s/%s", isolinux_dir, efi_cfg_name[i]); static_sprintf(path, "%s/%s", isolinux_dir, efi_cfg_name[i]);
fprintf(fd, "DEFAULT loadconfig\n\nLABEL loadconfig\n CONFIG %s\n APPEND %s\n", &path[2], &isolinux_dir[2]); fprintf(fd, "DEFAULT loadconfig\n\nLABEL loadconfig\n CONFIG %s\n APPEND %s\n", &path[2], &isolinux_dir[2]);
fclose(fd); fclose(fd);
for (j = 0; j < len; j++) to_windows_path(symlinked_syslinux);
if (symlinked_syslinux[j] == '/')
symlinked_syslinux[j] = '\\';
uprintf("Created: %s\\%s → %s", symlinked_syslinux, efi_cfg_name[i], &path[2]); uprintf("Created: %s\\%s → %s", symlinked_syslinux, efi_cfg_name[i], &path[2]);
for (j = 0; j < len; j++) to_unix_path(symlinked_syslinux);
if (symlinked_syslinux[j] == '\\')
symlinked_syslinux[j] = '/';
fd = NULL; fd = NULL;
} }
} }
@ -1390,7 +1381,7 @@ out:
uint32_t GetInstallWimVersion(const char* iso) uint32_t GetInstallWimVersion(const char* iso)
{ {
char *wim_path = NULL, *p, buf[UDF_BLOCKSIZE] = { 0 }; char *wim_path = NULL, buf[UDF_BLOCKSIZE] = { 0 };
uint32_t* wim_header = (uint32_t*)buf, r = 0xffffffff; uint32_t* wim_header = (uint32_t*)buf, r = 0xffffffff;
iso9660_t* p_iso = NULL; iso9660_t* p_iso = NULL;
udf_t* p_udf = NULL; udf_t* p_udf = NULL;
@ -1402,8 +1393,7 @@ uint32_t GetInstallWimVersion(const char* iso)
goto out; goto out;
// UDF indiscriminately accepts slash or backslash delimiters, // UDF indiscriminately accepts slash or backslash delimiters,
// but ISO-9660 requires slash // but ISO-9660 requires slash
for (p = wim_path; *p != 0; p++) to_unix_path(wim_path);
if (*p == '\\') *p = '/';
// First try to open as UDF - fallback to ISO if it failed // First try to open as UDF - fallback to ISO if it failed
p_udf = udf_open(iso); p_udf = udf_open(iso);

View file

@ -160,12 +160,16 @@
#define safe_atoi(str) ((((char*)(str))==NULL)?0:atoi(str)) #define safe_atoi(str) ((((char*)(str))==NULL)?0:atoi(str))
#define safe_strlen(str) ((((char*)(str))==NULL)?0:strlen(str)) #define safe_strlen(str) ((((char*)(str))==NULL)?0:strlen(str))
#define safe_strdup _strdup #define safe_strdup _strdup
#define to_windows_path(str) do { size_t __i; for (__i = 0; __i < safe_strlen(str); __i++) if (str[__i] == '/') str[__i] = '\\'; } while(0)
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define safe_vsnprintf(buf, size, format, arg) _vsnprintf_s(buf, size, _TRUNCATE, format, arg) #define safe_vsnprintf(buf, size, format, arg) _vsnprintf_s(buf, size, _TRUNCATE, format, arg)
#else #else
#define safe_vsnprintf vsnprintf #define safe_vsnprintf vsnprintf
#endif #endif
static __inline void static_repchr(char* p, char s, char r) {
if (p != NULL) while (*p != 0) { if (*p == s) *p = r; p++; }
}
#define to_unix_path(str) static_repchr(str, '\\', '/')
#define to_windows_path(str) static_repchr(str, '/', '\\')
extern void _uprintf(const char *format, ...); extern void _uprintf(const char *format, ...);
extern void _uprintfs(const char *str); extern void _uprintfs(const char *str);

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.20.1917" CAPTION "Rufus 3.20.1918"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,20,1917,0 FILEVERSION 3,20,1918,0
PRODUCTVERSION 3,20,1917,0 PRODUCTVERSION 3,20,1918,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.20.1917" VALUE "FileVersion", "3.20.1918"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2022 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2022 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.20.exe" VALUE "OriginalFilename", "rufus-3.20.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.20.1917" VALUE "ProductVersion", "3.20.1918"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"