Add optional versioned server file checker

If users have downloaded prebuilt server file, they may forget to update
the server file simply because they are all named "scrcpy-server". It is
already known to cause issues when server and client versions mismatch.
Let it check for "scrcpy-server-v<VERSION>" first (just as how it is
named in Github release page), then fall back to "scrcpy-server".

This mechanism is fully optional: users may still use the old unversioned
name "scrcpy-server"; or they can directly download server file from
release page without renaming it, and they will be notified to update
their server file because client cannot find either files (with the
correct version).
This commit is contained in:
yangfl 2024-08-06 08:36:48 +08:00
parent dd47cefa47
commit 4867a9b448

View file

@ -16,6 +16,8 @@
#include "util/str.h" #include "util/str.h"
#define SC_SERVER_FILENAME "scrcpy-server" #define SC_SERVER_FILENAME "scrcpy-server"
#define SC_SERVER_FILENAME_SUFFIX "-v" SCRCPY_VERSION
#define SC_SERVER_FULL_FILENAME SC_SERVER_FILENAME SC_SERVER_FILENAME_SUFFIX
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME #define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar" #define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
@ -53,11 +55,28 @@ get_server_path(void) {
return NULL; return NULL;
} }
#else #else
char *server_path = sc_file_get_local_path(SC_SERVER_FILENAME); char *server_path = sc_file_get_local_path(SC_SERVER_FULL_FILENAME);
if (!server_path) { if (!server_path) {
LOGE("Could not get local file path, " LOGE("Could not get path of the executable file itself, "
"using " SC_SERVER_FILENAME " from current directory"); "searching from current working directory");
return strdup(SC_SERVER_FILENAME); server_path = strdup(SC_SERVER_FULL_FILENAME);
if (!server_path) {
LOG_OOM();
return NULL;
}
}
if (!sc_file_is_regular(server_path)) {
// versioned server file not found; give another try
int i_sep = strlen(server_path) - strlen(SC_SERVER_FILENAME_SUFFIX);
server_path[i_sep] = '\0';
#ifndef __WINDOWS__
if (!sc_file_is_regular(server_path)) {
// Windows: just use the release zip
// non-Windows: suggest them to download versioned file
server_path[i_sep] = '-';
}
#endif
} }
LOGD("Using server (portable): %s", server_path); LOGD("Using server (portable): %s", server_path);