mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] save log and cache files into user folder
This commit is contained in:
@@ -171,7 +171,7 @@ Render::~Render() {}
|
||||
|
||||
int Render::SaveSettingsIntoCacheFile() {
|
||||
cd_cache_mutex_.lock();
|
||||
std::ofstream cd_cache_file("cache.cd", std::ios::binary);
|
||||
std::ofstream cd_cache_file(cache_path_ + "/cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file) {
|
||||
cd_cache_mutex_.unlock();
|
||||
return -1;
|
||||
@@ -212,7 +212,7 @@ int Render::SaveSettingsIntoCacheFile() {
|
||||
|
||||
int Render::LoadSettingsFromCacheFile() {
|
||||
cd_cache_mutex_.lock();
|
||||
std::ifstream cd_cache_file("cache.cd", std::ios::binary);
|
||||
std::ifstream cd_cache_file(cache_path_ + "/cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file) {
|
||||
cd_cache_mutex_.unlock();
|
||||
|
||||
@@ -235,7 +235,7 @@ int Render::LoadSettingsFromCacheFile() {
|
||||
config_center_.SetTurn(enable_turn_);
|
||||
|
||||
thumbnail_.reset();
|
||||
thumbnail_ = std::make_unique<Thumbnail>();
|
||||
thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/");
|
||||
thumbnail_->GetKeyAndIv(aes128_key_, aes128_iv_);
|
||||
thumbnail_->DeleteAllFilesInDirectory();
|
||||
|
||||
@@ -276,7 +276,8 @@ int Render::LoadSettingsFromCacheFile() {
|
||||
memcpy(aes128_iv_, cd_cache_.iv, sizeof(cd_cache_.iv));
|
||||
|
||||
thumbnail_.reset();
|
||||
thumbnail_ = std::make_unique<Thumbnail>(aes128_key_, aes128_iv_);
|
||||
thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/",
|
||||
aes128_key_, aes128_iv_);
|
||||
|
||||
language_button_value_ = cd_cache_.language;
|
||||
video_quality_button_value_ = cd_cache_.video_quality;
|
||||
@@ -351,7 +352,7 @@ int Render::ScreenCapturerInit() {
|
||||
|
||||
int Render::StartScreenCapturer() {
|
||||
if (screen_capturer_) {
|
||||
LOG_INFO("Start screen capturer")
|
||||
LOG_INFO("Start screen capturer");
|
||||
screen_capturer_->Start();
|
||||
}
|
||||
|
||||
@@ -360,7 +361,7 @@ int Render::StartScreenCapturer() {
|
||||
|
||||
int Render::StopScreenCapturer() {
|
||||
if (screen_capturer_) {
|
||||
LOG_INFO("Stop screen capturer")
|
||||
LOG_INFO("Stop screen capturer");
|
||||
screen_capturer_->Stop();
|
||||
}
|
||||
|
||||
@@ -407,7 +408,7 @@ int Render::StartMouseController() {
|
||||
|
||||
int mouse_controller_init_ret = mouse_controller_->Init(display_info_list_);
|
||||
if (0 != mouse_controller_init_ret) {
|
||||
LOG_INFO("Destroy mouse controller")
|
||||
LOG_INFO("Destroy mouse controller");
|
||||
mouse_controller_->Destroy();
|
||||
mouse_controller_ = nullptr;
|
||||
}
|
||||
@@ -465,7 +466,9 @@ int Render::CreateConnectionPeer() {
|
||||
params_.turn_server_port = 3478;
|
||||
params_.turn_server_username = "dijunkun";
|
||||
params_.turn_server_password = "dijunkunpw";
|
||||
params_.tls_cert_path = "certs/crossdesk.cn_root.crt";
|
||||
params_.tls_cert_path =
|
||||
cert_path_.empty() ? "certs/crossdesk.cn_root.crt" : cert_path_.c_str();
|
||||
params_.log_path = dll_log_path_.empty() ? "logs" : dll_log_path_.c_str();
|
||||
params_.hardware_acceleration = config_center_.IsHardwareVideoCodec();
|
||||
params_.av1_encoding = config_center_.GetVideoEncodeFormat() ==
|
||||
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1
|
||||
@@ -704,6 +707,10 @@ int Render::DestroyStreamWindow() {
|
||||
int Render::SetupFontAndStyle() {
|
||||
// Setup Dear ImGui style
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
imgui_cache_path_ = cache_path_ + "/crossdesk.ini";
|
||||
io.IniFilename = imgui_cache_path_.c_str();
|
||||
|
||||
io.ConfigFlags |=
|
||||
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |=
|
||||
@@ -892,6 +899,16 @@ int Render::DrawStreamWindow() {
|
||||
}
|
||||
|
||||
int Render::Run() {
|
||||
path_manager_ = std::make_unique<PathManager>("CrossDesk");
|
||||
if (path_manager_) {
|
||||
cert_path_ =
|
||||
(path_manager_->GetCertPath() / "crossdesk.cn_root.crt").string();
|
||||
exec_log_path_ = path_manager_->GetLogPath().string();
|
||||
dll_log_path_ = path_manager_->GetLogPath().string();
|
||||
cache_path_ = path_manager_->GetCachePath().string();
|
||||
}
|
||||
|
||||
InitializeLogger();
|
||||
InitializeSettings();
|
||||
InitializeSDL();
|
||||
InitializeModules();
|
||||
@@ -907,6 +924,14 @@ int Render::Run() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Render::InitializeLogger() {
|
||||
if (!exec_log_path_.empty()) {
|
||||
InitLogger(exec_log_path_);
|
||||
} else {
|
||||
InitLogger("logs");
|
||||
}
|
||||
}
|
||||
|
||||
void Render::InitializeSettings() {
|
||||
LoadSettingsFromCacheFile();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "imgui_impl_sdlrenderer2.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "minirtc.h"
|
||||
#include "path_manager.h"
|
||||
#include "screen_capturer_factory.h"
|
||||
#include "speaker_capturer_factory.h"
|
||||
#include "thumbnail.h"
|
||||
@@ -118,6 +119,7 @@ class Render {
|
||||
int Run();
|
||||
|
||||
private:
|
||||
void InitializeLogger();
|
||||
void InitializeSettings();
|
||||
void InitializeSDL();
|
||||
void InitializeModules();
|
||||
@@ -254,10 +256,15 @@ class Render {
|
||||
ConfigCenter config_center_;
|
||||
ConfigCenter::LANGUAGE localization_language_ =
|
||||
ConfigCenter::LANGUAGE::CHINESE;
|
||||
std::unique_ptr<PathManager> path_manager_;
|
||||
std::string cert_path_;
|
||||
std::string exec_log_path_;
|
||||
std::string dll_log_path_;
|
||||
std::string cache_path_;
|
||||
std::string imgui_cache_path_;
|
||||
int localization_language_index_ = -1;
|
||||
int localization_language_index_last_ = -1;
|
||||
bool modules_inited_ = false;
|
||||
|
||||
/* ------ all windows property start ------ */
|
||||
float title_bar_width_ = 640;
|
||||
float title_bar_height_ = 30;
|
||||
|
||||
@@ -127,16 +127,25 @@ void ScaleNv12ToABGR(char* src, int src_w, int src_h, int dst_w, int dst_h,
|
||||
}
|
||||
}
|
||||
|
||||
Thumbnail::Thumbnail() {
|
||||
Thumbnail::Thumbnail(std::string save_path) {
|
||||
if (!save_path.empty()) {
|
||||
save_path_ = save_path;
|
||||
}
|
||||
|
||||
RAND_bytes(aes128_key_, sizeof(aes128_key_));
|
||||
RAND_bytes(aes128_iv_, sizeof(aes128_iv_));
|
||||
std::filesystem::create_directory(image_path_);
|
||||
std::filesystem::create_directory(save_path_);
|
||||
}
|
||||
|
||||
Thumbnail::Thumbnail(unsigned char* aes128_key, unsigned char* aes128_iv) {
|
||||
Thumbnail::Thumbnail(std::string save_path, unsigned char* aes128_key,
|
||||
unsigned char* aes128_iv) {
|
||||
if (!save_path.empty()) {
|
||||
save_path_ = save_path;
|
||||
}
|
||||
|
||||
memcpy(aes128_key_, aes128_key, sizeof(aes128_key_));
|
||||
memcpy(aes128_iv_, aes128_iv, sizeof(aes128_iv_));
|
||||
std::filesystem::create_directory(image_path_);
|
||||
std::filesystem::create_directory(save_path_);
|
||||
}
|
||||
|
||||
Thumbnail::~Thumbnail() {
|
||||
@@ -177,7 +186,7 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height,
|
||||
|
||||
std::string cipher_password = AES_encrypt(password, aes128_key_, aes128_iv_);
|
||||
image_file_name = remote_id + 'Y' + host_name + '@' + cipher_password;
|
||||
std::string file_path = image_path_ + image_file_name;
|
||||
std::string file_path = save_path_ + image_file_name;
|
||||
stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4,
|
||||
rgba_buffer_, thumbnail_width_ * 4);
|
||||
|
||||
@@ -197,14 +206,14 @@ int Thumbnail::LoadThumbnail(
|
||||
recent_connections.clear();
|
||||
|
||||
std::vector<std::filesystem::path> image_paths =
|
||||
FindThumbnailPath(image_path_);
|
||||
FindThumbnailPath(save_path_);
|
||||
|
||||
if (image_paths.size() == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
for (int i = 0; i < image_paths.size(); i++) {
|
||||
size_t pos1 = image_paths[i].string().find('/') + 1;
|
||||
std::string cipher_image_name = image_paths[i].string().substr(pos1);
|
||||
std::string cipher_image_name = image_paths[i].filename().string();
|
||||
std::string remote_id;
|
||||
std::string cipher_password;
|
||||
std::string remote_host_name;
|
||||
@@ -245,7 +254,7 @@ int Thumbnail::LoadThumbnail(
|
||||
AES_decrypt(cipher_password, aes128_key_, aes128_iv_);
|
||||
}
|
||||
|
||||
std::string image_path = image_path_ + cipher_image_name;
|
||||
std::string image_path = save_path_ + cipher_image_name;
|
||||
recent_connections[original_image_name].texture = nullptr;
|
||||
LoadTextureFromFile(image_path.c_str(), renderer,
|
||||
&(recent_connections[original_image_name].texture),
|
||||
@@ -257,7 +266,7 @@ int Thumbnail::LoadThumbnail(
|
||||
}
|
||||
|
||||
int Thumbnail::DeleteThumbnail(const std::string& filename_keyword) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(image_path_)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(save_path_)) {
|
||||
if (entry.is_regular_file()) {
|
||||
const std::string filename = entry.path().filename().string();
|
||||
std::string id_hostname = filename_keyword.substr(0, filename.find('@'));
|
||||
@@ -295,9 +304,9 @@ std::vector<std::filesystem::path> Thumbnail::FindThumbnailPath(
|
||||
}
|
||||
|
||||
int Thumbnail::DeleteAllFilesInDirectory() {
|
||||
if (std::filesystem::exists(image_path_) &&
|
||||
std::filesystem::is_directory(image_path_)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(image_path_)) {
|
||||
if (std::filesystem::exists(save_path_) &&
|
||||
std::filesystem::is_directory(save_path_)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(save_path_)) {
|
||||
if (std::filesystem::is_regular_file(entry.status())) {
|
||||
std::filesystem::remove(entry.path());
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@ class Thumbnail {
|
||||
};
|
||||
|
||||
public:
|
||||
Thumbnail();
|
||||
explicit Thumbnail(unsigned char* aes128_key, unsigned char* aes128_iv);
|
||||
Thumbnail(std::string save_path);
|
||||
explicit Thumbnail(std::string save_path, unsigned char* aes128_key,
|
||||
unsigned char* aes128_iv);
|
||||
~Thumbnail();
|
||||
|
||||
public:
|
||||
@@ -74,7 +75,7 @@ class Thumbnail {
|
||||
int thumbnail_width_ = 160;
|
||||
int thumbnail_height_ = 90;
|
||||
char* rgba_buffer_ = nullptr;
|
||||
std::string image_path_ = "thumbnails/";
|
||||
std::string save_path_ = "thumbnails/";
|
||||
|
||||
unsigned char aes128_key_[16];
|
||||
unsigned char aes128_iv_[16];
|
||||
|
||||
Reference in New Issue
Block a user