From 4867a9b448d08a206cb659261df92097b0ebacb2 Mon Sep 17 00:00:00 2001 From: yangfl Date: Tue, 6 Aug 2024 08:36:48 +0800 Subject: [PATCH] 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" 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). --- app/src/server.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/server.c b/app/src/server.c index 41517f18..5c72da84 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -16,6 +16,8 @@ #include "util/str.h" #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_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar" @@ -53,11 +55,28 @@ get_server_path(void) { return NULL; } #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) { - LOGE("Could not get local file path, " - "using " SC_SERVER_FILENAME " from current directory"); - return strdup(SC_SERVER_FILENAME); + LOGE("Could not get path of the executable file itself, " + "searching from current working directory"); + 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);