Files
MINGW-packages/mingw-w64-mdloader/01-get-applet-path.patch
Johannes Schindelin 591d5bc677 mdloader: synchronize with mingw-w64-pathtools
Just like `mingw-w64-curl`, `mingw-w64-mdloader` is now also built with
a literal copy of `mingw-w64-pathtools`' source code.

This adds the `get_dll_path()` function (which is unused by the
`mdloader` code), and it also forward-ports the patch where we now
preserve UNC paths when normalizing/simplifying paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-07-19 17:31:09 +02:00

79 lines
2.1 KiB
Diff

--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
SRCFILES = mdloader_common.c mdloader_parser.c
ifeq ($(OS),Windows_NT)
-SRCFILES += mdloader_win32.c
+SRCFILES += mdloader_win32.c pathtools.c
else
SRCFILES += mdloader_unix.c
endif
--- a/mdloader_common.c
+++ b/mdloader_common.c
@@ -19,6 +19,7 @@
#include "mdloader_common.h"
#include "mdloader_parser.h"
+#include "pathtools.h"
char verbose;
char testmode;
@@ -179,6 +180,14 @@
return 1;
}
+void get_applet_path(char *filename, char *applet_path)
+{
+ get_executable_path(NULL, applet_path, PATH_MAX);
+ strip_n_suffix_folders(applet_path, 2);
+ strcat(applet_path, "/share/mdloader/");
+ strcat(applet_path, filename);
+}
+
//Run applet command and wait for device response
//Return 1 on sucess, 0 on failure
int run_applet(mailbox_t *mail)
@@ -754,14 +763,21 @@
//Load applet
FILE *fIn;
char appletfname[128] = "";
+ char appletfpath[PATH_MAX];
strlower(mcu->name);
//sprintf(appletfname, "applet-flash-%s.bin", mcu->name);
sprintf(appletfname, "applet-mdflash.bin"); //make filename non-dependent upon mcu->name
+ strcpy(appletfpath, appletfname);
printf("Applet file: %s\n", appletfname);
- fIn = fopen(appletfname, "rb");
+ fIn = fopen(appletfpath, "rb"); // Try in CWD first
+ if (!fIn)
+ {
+ get_applet_path(appletfname, appletfpath); // If not in CWD, look in $PREFIX/share/mdloader
+ fIn = fopen(appletfpath, "rb");
+ }
if (!fIn)
{
printf("Error: Could not open applet file: %s\n", appletfname);
@@ -773,7 +789,7 @@
int filebytes;
int readbytes;
- filebytes = filesize(appletfname);
+ filebytes = filesize(appletfpath);
if (filebytes == 0)
{
printf("Error: Applet file is empty!\n");
--- a/mdloader_common.h
+++ b/mdloader_common.h
@@ -129,6 +129,7 @@
#define APPLET_RETRY_NORMAL 10 //Normal operation retries
#define APPLET_RETRY_ERASE 25 //Erase operation retries
+void get_applet_path(char *filename, char *applet_path);
int run_applet(mailbox_t *mail);
void display_version(void);