Skip to content

Commit

Permalink
Add optional versioned server file checker
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
yangfl committed Aug 6, 2024
1 parent dd47cef commit da25bf5
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit da25bf5

Please sign in to comment.