add: meta info
This commit is contained in:
parent
529e5104c7
commit
74a3799b78
@ -304,6 +304,14 @@ message FileTransferSendConfirmRequest {
|
||||
}
|
||||
}
|
||||
|
||||
message FileTransferDirOffsetRequest {
|
||||
int32 id = 1;
|
||||
// start from file_num
|
||||
sint32 file_num = 2;
|
||||
// current file blk offset
|
||||
uint32 offset_blk = 3;
|
||||
}
|
||||
|
||||
message FileTransferDone {
|
||||
int32 id = 1;
|
||||
sint32 file_num = 2;
|
||||
|
@ -1,8 +1,3 @@
|
||||
use crate::log;
|
||||
use directories_next::ProjectDirs;
|
||||
use rand::Rng;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sodiumoxide::crypto::sign;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
@ -145,6 +140,8 @@ pub struct PeerConfig {
|
||||
pub options: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub info: PeerInfoSerde,
|
||||
#[serde(default)]
|
||||
pub transfer: TransferSerde,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
||||
@ -157,6 +154,16 @@ pub struct PeerInfoSerde {
|
||||
pub platform: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct TransferSerde {
|
||||
#[serde(default)]
|
||||
pub write_jobs: Vec<TransferJobMeta>,
|
||||
#[serde(default)]
|
||||
pub read_jobs: Vec<TransferJobMeta>,
|
||||
#[serde(default)]
|
||||
pub remove_jobs: Vec<RemoveJobMeta>,
|
||||
}
|
||||
|
||||
fn patch(path: PathBuf) -> PathBuf {
|
||||
if let Some(_tmp) = path.to_str() {
|
||||
#[cfg(windows)]
|
||||
@ -864,6 +871,7 @@ impl LanPeers {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_serialize() {
|
||||
let cfg: Config = Default::default();
|
||||
|
@ -1,14 +1,17 @@
|
||||
use crate::{bail, get_version_number, message_proto::*, ResultType, Stream};
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tokio::{fs::File, io::*};
|
||||
|
||||
use crate::{bail, get_version_number, message_proto::*, ResultType, Stream};
|
||||
// https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html
|
||||
use crate::{
|
||||
compress::{compress, decompress},
|
||||
config::{Config, COMPRESS_LEVEL},
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::prelude::*;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use tokio::{fs::File, io::*};
|
||||
|
||||
pub fn read_dir(path: &PathBuf, include_hidden: bool) -> ResultType<FileDirectory> {
|
||||
let mut dir = FileDirectory {
|
||||
@ -211,6 +214,20 @@ pub struct TransferJob {
|
||||
default_overwrite_strategy: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct TransferJobMeta {
|
||||
pub id: i32,
|
||||
pub path: PathBuf,
|
||||
pub file_num: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct RemoveJobMeta {
|
||||
pub path: String,
|
||||
pub is_remote: bool,
|
||||
pub no_confirm: bool,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_ext(name: &str) -> &str {
|
||||
if let Some(i) = name.rfind(".") {
|
||||
@ -540,6 +557,14 @@ impl TransferJob {
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn gen_meta(&self) -> TransferJobMeta {
|
||||
TransferJobMeta {
|
||||
id: self.id,
|
||||
path: self.path.clone(),
|
||||
file_num: self.file_num,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1,9 +1,20 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::SocketAddr,
|
||||
ops::Deref,
|
||||
sync::{mpsc, Arc, RwLock},
|
||||
};
|
||||
|
||||
pub use async_trait::async_trait;
|
||||
#[cfg(not(any(target_os = "android", target_os = "linux")))]
|
||||
use cpal::{
|
||||
traits::{DeviceTrait, HostTrait, StreamTrait},
|
||||
Device, Host, StreamConfig,
|
||||
};
|
||||
use magnum_opus::{Channels::*, Decoder as AudioDecoder};
|
||||
use sha2::{Digest, Sha256};
|
||||
use uuid::Uuid;
|
||||
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::{anyhow, Context},
|
||||
@ -19,24 +30,15 @@ use hbb_common::{
|
||||
tokio::time::Duration,
|
||||
AddrMangle, ResultType, Stream,
|
||||
};
|
||||
use magnum_opus::{Channels::*, Decoder as AudioDecoder};
|
||||
use scrap::{Decoder, Image, VideoCodecId};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::SocketAddr,
|
||||
ops::Deref,
|
||||
sync::{mpsc, Arc, RwLock},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use super::lang::*;
|
||||
pub mod file_trait;
|
||||
pub use file_trait::FileManager;
|
||||
pub const SEC30: Duration = Duration::from_secs(30);
|
||||
|
||||
pub struct Client;
|
||||
|
||||
pub use super::lang::*;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "linux")))]
|
||||
lazy_static::lazy_static! {
|
||||
static ref AUDIO_HOST: Host = cpal::default_host();
|
||||
@ -1324,6 +1326,7 @@ pub enum Data {
|
||||
ToggleClipboardFile,
|
||||
NewRDP,
|
||||
SetConfirmOverrideFile((i32, i32, bool, bool, bool)),
|
||||
ResumeTransfer,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,18 +1,29 @@
|
||||
#[cfg(windows)]
|
||||
use crate::clipboard_file::*;
|
||||
use crate::{
|
||||
client::*,
|
||||
common::{self, check_clipboard, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL},
|
||||
VERSION,
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::Deref,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
};
|
||||
|
||||
use sciter::{
|
||||
dom::{
|
||||
event::{EventReason, BEHAVIOR_EVENTS, EVENT_GROUPS, PHASE_MASK},
|
||||
Element, HELEMENT,
|
||||
},
|
||||
make_args,
|
||||
video::{video_destination, AssetPtr, COLOR_SPACE},
|
||||
Value,
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
use clipboard::{
|
||||
cliprdr::CliprdrClientContext, create_cliprdr_context as create_clipboard_file_context,
|
||||
get_rx_clip_client, server_clip_file,
|
||||
};
|
||||
use enigo::{self, Enigo, KeyboardControllable};
|
||||
use hbb_common::config::TransferSerde;
|
||||
use hbb_common::fs::{
|
||||
can_enable_overwrite_detection, get_string, is_file_exists, new_send_confirm, DigestCheckResult,
|
||||
can_enable_overwrite_detection, get_string, is_file_exists, new_send_confirm,
|
||||
DigestCheckResult, RemoveJobMeta,
|
||||
};
|
||||
use hbb_common::log::log;
|
||||
use hbb_common::{
|
||||
@ -30,19 +41,13 @@ use hbb_common::{
|
||||
},
|
||||
Stream,
|
||||
};
|
||||
use sciter::{
|
||||
dom::{
|
||||
event::{EventReason, BEHAVIOR_EVENTS, EVENT_GROUPS, PHASE_MASK},
|
||||
Element, HELEMENT,
|
||||
},
|
||||
make_args,
|
||||
video::{video_destination, AssetPtr, COLOR_SPACE},
|
||||
Value,
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::Deref,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
|
||||
#[cfg(windows)]
|
||||
use crate::clipboard_file::*;
|
||||
use crate::{
|
||||
client::*,
|
||||
common::{self, check_clipboard, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL},
|
||||
VERSION,
|
||||
};
|
||||
|
||||
type Video = AssetPtr<video_destination>;
|
||||
@ -1314,6 +1319,7 @@ async fn io_loop(handler: Handler) {
|
||||
clipboard_file_context: None,
|
||||
};
|
||||
remote.io_loop(&key, &token).await;
|
||||
remote.sync_jobs_status_to_local();
|
||||
}
|
||||
|
||||
struct RemoveJob {
|
||||
@ -1336,6 +1342,14 @@ impl RemoveJob {
|
||||
last_update_job_status: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gen_meta(&self) -> RemoveJobMeta {
|
||||
RemoveJobMeta {
|
||||
path: self.path.clone(),
|
||||
is_remote: self.is_remote,
|
||||
no_confirm: self.no_confirm,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Remote {
|
||||
@ -1438,6 +1452,7 @@ impl Remote {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.sync_jobs_status_to_local();
|
||||
log::debug!("Exit io_loop of id={}", self.handler.id);
|
||||
}
|
||||
Err(err) => {
|
||||
@ -1782,6 +1797,23 @@ impl Remote {
|
||||
}
|
||||
}
|
||||
|
||||
async fn sync_jobs_status_to_local(&mut self) -> bool {
|
||||
let mut config: PeerConfig = self.handler.load_config();
|
||||
let mut transfer_metas = TransferSerde::default();
|
||||
for job in self.read_jobs.iter() {
|
||||
transfer_metas.read_jobs.push(job.gen_meta());
|
||||
}
|
||||
for job in self.write_jobs.iter() {
|
||||
transfer_metas.write_jobs.push(job.gen_meta());
|
||||
}
|
||||
for job in self.remove_jobs.values() {
|
||||
transfer_metas.remove_jobs.push(job.gen_meta());
|
||||
}
|
||||
config.transfer = transfer_metas;
|
||||
self.handler.save_config(config);
|
||||
true
|
||||
}
|
||||
|
||||
async fn handle_msg_from_peer(&mut self, data: &[u8], peer: &mut Stream) -> bool {
|
||||
if let Ok(msg_in) = Message::parse_from_bytes(&data) {
|
||||
match msg_in.union {
|
||||
|
Loading…
x
Reference in New Issue
Block a user