Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional versioned server file checker #5172

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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