Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6eabe5a8bc | ||
|
9988d6186e | ||
|
451f3ed309 | ||
|
5142e0e621 | ||
|
e9bacc196a |
@ -57,7 +57,7 @@ build-win32: prepare-deps-win32
|
|||||||
--buildtype release --strip -Db_lto=true \
|
--buildtype release --strip -Db_lto=true \
|
||||||
-Dcrossbuild_windows=true \
|
-Dcrossbuild_windows=true \
|
||||||
-Dbuild_server=false \
|
-Dbuild_server=false \
|
||||||
-Doverride_server_path=scrcpy-server.jar )
|
-Dportable=true )
|
||||||
ninja -C "$(WIN32_BUILD_DIR)"
|
ninja -C "$(WIN32_BUILD_DIR)"
|
||||||
|
|
||||||
build-win32-noconsole: prepare-deps-win32
|
build-win32-noconsole: prepare-deps-win32
|
||||||
@ -68,7 +68,7 @@ build-win32-noconsole: prepare-deps-win32
|
|||||||
-Dcrossbuild_windows=true \
|
-Dcrossbuild_windows=true \
|
||||||
-Dbuild_server=false \
|
-Dbuild_server=false \
|
||||||
-Dwindows_noconsole=true \
|
-Dwindows_noconsole=true \
|
||||||
-Doverride_server_path=scrcpy-server.jar )
|
-Dportable=true )
|
||||||
ninja -C "$(WIN32_NOCONSOLE_BUILD_DIR)"
|
ninja -C "$(WIN32_NOCONSOLE_BUILD_DIR)"
|
||||||
|
|
||||||
prepare-deps-win64:
|
prepare-deps-win64:
|
||||||
@ -81,7 +81,7 @@ build-win64: prepare-deps-win64
|
|||||||
--buildtype release --strip -Db_lto=true \
|
--buildtype release --strip -Db_lto=true \
|
||||||
-Dcrossbuild_windows=true \
|
-Dcrossbuild_windows=true \
|
||||||
-Dbuild_server=false \
|
-Dbuild_server=false \
|
||||||
-Doverride_server_path=scrcpy-server.jar )
|
-Dportable=true )
|
||||||
ninja -C "$(WIN64_BUILD_DIR)"
|
ninja -C "$(WIN64_BUILD_DIR)"
|
||||||
|
|
||||||
build-win64-noconsole: prepare-deps-win64
|
build-win64-noconsole: prepare-deps-win64
|
||||||
@ -92,7 +92,7 @@ build-win64-noconsole: prepare-deps-win64
|
|||||||
-Dcrossbuild_windows=true \
|
-Dcrossbuild_windows=true \
|
||||||
-Dbuild_server=false \
|
-Dbuild_server=false \
|
||||||
-Dwindows_noconsole=true \
|
-Dwindows_noconsole=true \
|
||||||
-Doverride_server_path=scrcpy-server.jar )
|
-Dportable=true )
|
||||||
ninja -C "$(WIN64_NOCONSOLE_BUILD_DIR)"
|
ninja -C "$(WIN64_NOCONSOLE_BUILD_DIR)"
|
||||||
|
|
||||||
dist-win32: build-server build-win32 build-win32-noconsole
|
dist-win32: build-server build-win32 build-win32-noconsole
|
||||||
|
@ -93,21 +93,9 @@ conf.set_quoted('SCRCPY_VERSION', meson.project_version())
|
|||||||
# the prefix used during configuration (meson --prefix=PREFIX)
|
# the prefix used during configuration (meson --prefix=PREFIX)
|
||||||
conf.set_quoted('PREFIX', get_option('prefix'))
|
conf.set_quoted('PREFIX', get_option('prefix'))
|
||||||
|
|
||||||
# the path of the server, which will be appended to the prefix
|
# build a "portable" version (with scrcpy-server.jar accessible from the same
|
||||||
# ignored if OVERRIDE_SERVER_PATH if defined
|
# directory as the executable)
|
||||||
# must be consistent with the install_dir in server/meson.build
|
conf.set('PORTABLE', get_option('portable'))
|
||||||
conf.set_quoted('PREFIXED_SERVER_PATH', '/share/scrcpy/scrcpy-server.jar')
|
|
||||||
|
|
||||||
# the path of the server to be used "as is"
|
|
||||||
# this is useful for building a "portable" version (with the server in the same
|
|
||||||
# directory as the client)
|
|
||||||
override_server_path = get_option('override_server_path')
|
|
||||||
if override_server_path != ''
|
|
||||||
conf.set_quoted('OVERRIDE_SERVER_PATH', override_server_path)
|
|
||||||
else
|
|
||||||
# undefine it
|
|
||||||
conf.set('OVERRIDE_SERVER_PATH', false)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# the default client TCP port for the "adb reverse" tunnel
|
# the default client TCP port for the "adb reverse" tunnel
|
||||||
# overridden by option --port
|
# overridden by option --port
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
// not needed here, but winsock2.h must never be included AFTER windows.h
|
// not needed here, but winsock2.h must never be included AFTER windows.h
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
# define PATH_SEPARATOR '\\'
|
||||||
# define PRIexitcode "lu"
|
# define PRIexitcode "lu"
|
||||||
// <https://stackoverflow.com/a/44383330/1987178>
|
// <https://stackoverflow.com/a/44383330/1987178>
|
||||||
# ifdef _WIN64
|
# ifdef _WIN64
|
||||||
@ -23,6 +24,7 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
# define PATH_SEPARATOR '/'
|
||||||
# define PRIsizet "zu"
|
# define PRIsizet "zu"
|
||||||
# define PRIexitcode "d"
|
# define PRIexitcode "d"
|
||||||
# define PROCESS_NONE -1
|
# define PROCESS_NONE -1
|
||||||
@ -76,4 +78,9 @@ adb_install(const char *serial, const char *local);
|
|||||||
bool
|
bool
|
||||||
process_check_success(process_t proc, const char *name);
|
process_check_success(process_t proc, const char *name);
|
||||||
|
|
||||||
|
// return the absolute path of the executable (the scrcpy binary)
|
||||||
|
// may be NULL on error; to be freed by SDL_free
|
||||||
|
char *
|
||||||
|
get_executable_path(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,31 +2,67 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "command.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
#define SOCKET_NAME "scrcpy"
|
#define SOCKET_NAME "scrcpy"
|
||||||
|
#define SERVER_FILENAME "scrcpy-server.jar"
|
||||||
|
|
||||||
#ifdef OVERRIDE_SERVER_PATH
|
#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FLENAME
|
||||||
# define DEFAULT_SERVER_PATH OVERRIDE_SERVER_PATH
|
#define DEVICE_SERVER_PATH "/data/local/tmp/" SERVER_FILENAME
|
||||||
#else
|
|
||||||
# define DEFAULT_SERVER_PATH PREFIX PREFIXED_SERVER_PATH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
get_server_path(void) {
|
get_server_path(void) {
|
||||||
const char *server_path = getenv("SCRCPY_SERVER_PATH");
|
const char *server_path_env = getenv("SCRCPY_SERVER_PATH");
|
||||||
if (!server_path) {
|
if (server_path_env) {
|
||||||
server_path = DEFAULT_SERVER_PATH;
|
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path_env);
|
||||||
|
// if the envvar is set, use it
|
||||||
|
return server_path_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef PORTABLE
|
||||||
|
LOGD("Using server: " DEFAULT_SERVER_PATH);
|
||||||
|
// the absolute path is hardcoded
|
||||||
|
return DEFAULT_SERVER_PATH;
|
||||||
|
#else
|
||||||
|
// use scrcpy-server.jar in the same directory as the executable
|
||||||
|
char *executable_path = get_executable_path();
|
||||||
|
if (!executable_path) {
|
||||||
|
LOGE("Cannot get executable path, "
|
||||||
|
"using " SERVER_FILENAME " from current directory");
|
||||||
|
// not found, use current directory
|
||||||
|
return SERVER_FILENAME;
|
||||||
|
}
|
||||||
|
char *dir = dirname(executable_path);
|
||||||
|
size_t dirlen = strlen(dir);
|
||||||
|
|
||||||
|
// sizeof(SERVER_FILENAME) gives statically the size including the null byte
|
||||||
|
size_t len = dirlen + 1 + sizeof(SERVER_FILENAME);
|
||||||
|
char *server_path = SDL_malloc(len);
|
||||||
|
if (!server_path) {
|
||||||
|
LOGE("Cannot alloc server path string, "
|
||||||
|
"using " SERVER_FILENAME " from current directory");
|
||||||
|
SDL_free(executable_path);
|
||||||
|
return SERVER_FILENAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(server_path, dir, dirlen);
|
||||||
|
server_path[dirlen] = PATH_SEPARATOR;
|
||||||
|
memcpy(&server_path[dirlen + 1], SERVER_FILENAME, sizeof(SERVER_FILENAME));
|
||||||
|
// the final null byte has been copied with SERVER_FILENAME
|
||||||
|
|
||||||
|
SDL_free(executable_path);
|
||||||
|
|
||||||
|
LOGD("Using server (portable): %s", server_path);
|
||||||
return server_path;
|
return server_path;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@ -86,7 +122,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
||||||
const char *const cmd[] = {
|
const char *const cmd[] = {
|
||||||
"shell",
|
"shell",
|
||||||
"CLASSPATH=/data/local/tmp/scrcpy-server.jar",
|
"CLASSPATH=/data/local/tmp/" SERVER_FILENAME,
|
||||||
"app_process",
|
"app_process",
|
||||||
"/", // unused
|
"/", // unused
|
||||||
"com.genymobile.scrcpy.Server",
|
"com.genymobile.scrcpy.Server",
|
||||||
|
@ -92,4 +92,20 @@ utf8_to_wide_char(const char *utf8) {
|
|||||||
return wide;
|
return wide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
utf8_from_wide_char(const wchar_t *ws) {
|
||||||
|
int len = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
|
||||||
|
if (!len) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *utf8 = SDL_malloc(len);
|
||||||
|
if (!utf8) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, ws, -1, utf8, len, NULL, NULL);
|
||||||
|
return utf8;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,6 +32,9 @@ utf8_truncation_index(const char *utf8, size_t max_len);
|
|||||||
// returns the new allocated string, to be freed by the caller
|
// returns the new allocated string, to be freed by the caller
|
||||||
wchar_t *
|
wchar_t *
|
||||||
utf8_to_wide_char(const char *utf8);
|
utf8_to_wide_char(const char *utf8);
|
||||||
|
|
||||||
|
char *
|
||||||
|
utf8_from_wide_char(const wchar_t *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
|
// for portability
|
||||||
#define _POSIX_SOURCE // for kill()
|
#define _POSIX_SOURCE // for kill()
|
||||||
|
#define _BSD_SOURCE // for readlink()
|
||||||
|
|
||||||
|
// modern glibc will complain without this
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -98,3 +104,15 @@ cmd_simple_wait(pid_t pid, int *exit_code) {
|
|||||||
}
|
}
|
||||||
return !code;
|
return !code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
get_executable_path(void) {
|
||||||
|
char buf[PATH_MAX + 1]; // +1 for the null byte
|
||||||
|
ssize_t len = readlink("/proc/self/exe", buf, PATH_MAX);
|
||||||
|
if (len == -1) {
|
||||||
|
perror("readlink");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf[len] = '\0';
|
||||||
|
return SDL_strdup(buf);
|
||||||
|
}
|
||||||
|
@ -75,3 +75,18 @@ cmd_simple_wait(HANDLE handle, DWORD *exit_code) {
|
|||||||
}
|
}
|
||||||
return !code;
|
return !code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
get_executable_path(void) {
|
||||||
|
HMODULE hModule = GetModuleHandleW(NULL);
|
||||||
|
if (!hModule) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
WCHAR buf[MAX_PATH + 1]; // +1 for the null byte
|
||||||
|
int len = GetModuleFileNameW(hModule, buf, MAX_PATH);
|
||||||
|
if (!len) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf[len] = '\0';
|
||||||
|
return utf8_from_wide_char(buf);
|
||||||
|
}
|
||||||
|
@ -3,6 +3,6 @@ option('build_server', type: 'boolean', value: true, description: 'Build the ser
|
|||||||
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
||||||
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
||||||
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
||||||
option('override_server_path', type: 'string', description: 'Hardcoded path to find the server at runtime')
|
option('portable', type: 'boolean', description: 'Use scrcpy-server.jar from the same directory as the scrcpy executable')
|
||||||
option('skip_frames', type: 'boolean', value: true, description: 'Always display the most recent frame')
|
option('skip_frames', type: 'boolean', value: true, description: 'Always display the most recent frame')
|
||||||
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user