mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[fix] fix thumbnail filename which stores remote id, remote host name and remote password
This commit is contained in:
@@ -80,16 +80,34 @@ int Render::ShowRecentConnections() {
|
|||||||
|
|
||||||
// remote id length is 9
|
// remote id length is 9
|
||||||
// password length is 6
|
// password length is 6
|
||||||
// connection_info -> remote_id + 'Y' + password + host_name
|
// connection_info -> remote_id + 'Y' + host_name + '@' + password
|
||||||
// -> remote_id + 'N' + host_name
|
// -> remote_id + 'N' + host_name
|
||||||
if ('Y' == connection_info[9] && connection_info.size() >= 16) {
|
if ('Y' == connection_info[9] && connection_info.size() >= 16) {
|
||||||
it->second.remote_id = connection_info.substr(0, 9);
|
size_t pos_y = connection_info.find('Y');
|
||||||
it->second.password = connection_info.substr(10, 6);
|
size_t pos_at = connection_info.find('@');
|
||||||
it->second.remote_host_name = connection_info.substr(16);
|
|
||||||
|
if (pos_y == std::string::npos || pos_at == std::string::npos ||
|
||||||
|
pos_y >= pos_at) {
|
||||||
|
LOG_ERROR("Invalid filename");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second.remote_id = connection_info.substr(0, pos_y);
|
||||||
|
it->second.remote_host_name =
|
||||||
|
connection_info.substr(pos_y + 1, pos_at - pos_y - 1);
|
||||||
|
it->second.password = connection_info.substr(pos_at + 1);
|
||||||
it->second.remember_password = true;
|
it->second.remember_password = true;
|
||||||
} else if ('N' == connection_info[9] && connection_info.size() >= 10) {
|
} else if ('N' == connection_info[9] && connection_info.size() >= 10) {
|
||||||
it->second.remote_id = connection_info.substr(0, 9);
|
size_t pos_n = connection_info.find('N');
|
||||||
it->second.remote_host_name = connection_info.substr(10);
|
size_t pos_at = connection_info.find('@');
|
||||||
|
|
||||||
|
if (pos_n == std::string::npos) {
|
||||||
|
LOG_ERROR("Invalid filename");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second.remote_id = connection_info.substr(0, pos_n);
|
||||||
|
it->second.remote_host_name = connection_info.substr(pos_n + 1);
|
||||||
it->second.password = "";
|
it->second.password = "";
|
||||||
it->second.remember_password = false;
|
it->second.remember_password = false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -190,6 +190,8 @@ int Render::SaveSettingsIntoCacheFile() {
|
|||||||
memcpy(&cd_cache_.enable_hardware_video_codec, &enable_hardware_video_codec_,
|
memcpy(&cd_cache_.enable_hardware_video_codec, &enable_hardware_video_codec_,
|
||||||
sizeof(enable_hardware_video_codec_));
|
sizeof(enable_hardware_video_codec_));
|
||||||
memcpy(&cd_cache_.enable_turn, &enable_turn_, sizeof(enable_turn_));
|
memcpy(&cd_cache_.enable_turn, &enable_turn_, sizeof(enable_turn_));
|
||||||
|
memcpy(&cd_cache_.key, &aes128_key_, sizeof(aes128_key_));
|
||||||
|
memcpy(&cd_cache_.iv, &aes128_iv_, sizeof(aes128_iv_));
|
||||||
|
|
||||||
cd_cache_file.write(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
cd_cache_file.write(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
||||||
cd_cache_file.close();
|
cd_cache_file.close();
|
||||||
@@ -483,9 +485,9 @@ int Render::CreateConnectionPeer() {
|
|||||||
|
|
||||||
peer_ = CreatePeer(¶ms_);
|
peer_ = CreatePeer(¶ms_);
|
||||||
if (peer_) {
|
if (peer_) {
|
||||||
LOG_INFO("[{}] Create peer instance successful", client_id_);
|
LOG_INFO("Create peer instance [{}] successful", client_id_);
|
||||||
Init(peer_);
|
Init(peer_);
|
||||||
LOG_INFO("[{}] Peer init finish", client_id_);
|
LOG_INFO("Peer [{}] init finish", client_id_);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Create peer [{}] instance failed", client_id_);
|
LOG_INFO("Create peer [{}] instance failed", client_id_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,19 +166,18 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string image_name;
|
std::string image_file_name;
|
||||||
if (password.empty()) {
|
if (password.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
// delete the file which has no password in its name
|
// delete the old thumbnail
|
||||||
std::string filename_without_password = remote_id + "N" + host_name;
|
std::string filename_with_remote_id = remote_id;
|
||||||
DeleteThumbnail(filename_without_password);
|
DeleteThumbnail(filename_with_remote_id);
|
||||||
|
|
||||||
image_name = remote_id + 'Y' + password + host_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ciphertext = AES_encrypt(image_name, aes128_key_, aes128_iv_);
|
std::string cipher_password = AES_encrypt(password, aes128_key_, aes128_iv_);
|
||||||
std::string file_path = image_path_ + ciphertext;
|
image_file_name = remote_id + 'Y' + host_name + '@' + cipher_password;
|
||||||
|
std::string file_path = image_path_ + image_file_name;
|
||||||
stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4,
|
stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4,
|
||||||
rgba_buffer_, thumbnail_width_ * 4);
|
rgba_buffer_, thumbnail_width_ * 4);
|
||||||
|
|
||||||
@@ -206,8 +205,46 @@ int Thumbnail::LoadThumbnail(
|
|||||||
for (int i = 0; i < image_paths.size(); i++) {
|
for (int i = 0; i < image_paths.size(); i++) {
|
||||||
size_t pos1 = image_paths[i].string().find('/') + 1;
|
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].string().substr(pos1);
|
||||||
std::string original_image_name =
|
std::string remote_id;
|
||||||
AES_decrypt(cipher_image_name, aes128_key_, aes128_iv_);
|
std::string cipher_password;
|
||||||
|
std::string remote_host_name;
|
||||||
|
std::string original_image_name;
|
||||||
|
|
||||||
|
if ('Y' == cipher_image_name[9] && cipher_image_name.size() >= 16) {
|
||||||
|
size_t pos_y = cipher_image_name.find('Y');
|
||||||
|
size_t pos_at = cipher_image_name.find('@');
|
||||||
|
|
||||||
|
if (pos_y == std::string::npos || pos_at == std::string::npos ||
|
||||||
|
pos_y >= pos_at) {
|
||||||
|
LOG_ERROR("Invalid filename");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
remote_id = cipher_image_name.substr(0, pos_y);
|
||||||
|
remote_host_name =
|
||||||
|
cipher_image_name.substr(pos_y + 1, pos_at - pos_y - 1);
|
||||||
|
cipher_password = cipher_image_name.substr(pos_at + 1);
|
||||||
|
|
||||||
|
original_image_name =
|
||||||
|
remote_id + 'Y' + remote_host_name + "@" +
|
||||||
|
AES_decrypt(cipher_password, aes128_key_, aes128_iv_);
|
||||||
|
} else {
|
||||||
|
size_t pos_n = cipher_image_name.find('N');
|
||||||
|
size_t pos_at = cipher_image_name.find('@');
|
||||||
|
|
||||||
|
if (pos_n == std::string::npos) {
|
||||||
|
LOG_ERROR("Invalid filename");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
remote_id = cipher_image_name.substr(0, pos_n);
|
||||||
|
remote_host_name = cipher_image_name.substr(pos_n + 1);
|
||||||
|
|
||||||
|
original_image_name =
|
||||||
|
remote_id + 'N' + remote_host_name + "@" +
|
||||||
|
AES_decrypt(cipher_password, aes128_key_, aes128_iv_);
|
||||||
|
}
|
||||||
|
|
||||||
std::string image_path = image_path_ + cipher_image_name;
|
std::string image_path = image_path_ + cipher_image_name;
|
||||||
recent_connections[original_image_name].texture = nullptr;
|
recent_connections[original_image_name].texture = nullptr;
|
||||||
LoadTextureFromFile(image_path.c_str(), renderer,
|
LoadTextureFromFile(image_path.c_str(), renderer,
|
||||||
@@ -219,15 +256,17 @@ int Thumbnail::LoadThumbnail(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Thumbnail::DeleteThumbnail(const std::string& file_name) {
|
int Thumbnail::DeleteThumbnail(const std::string& filename_keyword) {
|
||||||
std::string ciphertext = AES_encrypt(file_name, aes128_key_, aes128_iv_);
|
for (const auto& entry : std::filesystem::directory_iterator(image_path_)) {
|
||||||
std::string file_path = image_path_ + ciphertext;
|
if (entry.is_regular_file()) {
|
||||||
if (std::filesystem::exists(file_path)) {
|
const std::string filename = entry.path().filename().string();
|
||||||
std::filesystem::remove(file_path);
|
if (filename.find(filename_keyword) != std::string::npos) {
|
||||||
return 0;
|
std::filesystem::remove(entry.path());
|
||||||
} else {
|
}
|
||||||
return -1;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::filesystem::path> Thumbnail::FindThumbnailPath(
|
std::vector<std::filesystem::path> Thumbnail::FindThumbnailPath(
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class Thumbnail {
|
|||||||
std::map<std::string, RecentConnection>& recent_connections,
|
std::map<std::string, RecentConnection>& recent_connections,
|
||||||
int* width, int* height);
|
int* width, int* height);
|
||||||
|
|
||||||
int DeleteThumbnail(const std::string& file_name);
|
int DeleteThumbnail(const std::string& filename_keyword);
|
||||||
|
|
||||||
int DeleteAllFilesInDirectory();
|
int DeleteAllFilesInDirectory();
|
||||||
|
|
||||||
|
|||||||
2
thirdparty/minirtc
vendored
2
thirdparty/minirtc
vendored
Submodule thirdparty/minirtc updated: 3686dd0019...2e1376a6c7
Reference in New Issue
Block a user