diff --git a/Changes.md b/Changes.md index 9e674bce..77624d9e 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,7 @@ +v1.1.2 +- change profile file's syntax +- update ios workflow + v1.1.1 - fix bug diff --git a/README.md b/README.md index a3975088..7c506352 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ [![Build status](https://ci.appveyor.com/api/projects/status/4hm1au4xaikj96tr?svg=true)](https://ci.appveyor.com/project/Jeric-X/syncclipboard) ## 功能 -一个简单的剪切板同步工具,使用网盘作为服务器,暂存剪切版内容,windows使用一个客户端自动更新或上传剪切版内容,IOS只能曲线救国手动使用APP`捷径`收发想要同步的内容了 +一个简单的剪切板同步工具,使用网盘作为中转站,支持文字和图片 +windows使用c#写了个客户端,IOS只能曲线救国使用APP`快捷指令`手动收发 ## Server @@ -19,7 +20,7 @@ ## Client-IOS 使用[Workflow](https://appsto.re/cn/2IzJ2.i)提供的`Get Contents of URL`功能发送HTTP协议 -导入这个[Workflow](https://workflow.is/workflows/6da4c1de8b1446cda56e336b1ed50b25) +导入这个[Workflow](https://www.icloud.com/shortcuts/229cd7657ce544daafc7ece882405b36) ## 配置 diff --git a/SyncClipboard/ConvertJsonClass.cs b/SyncClipboard/ConvertJsonClass.cs deleted file mode 100644 index 2152b06c..00000000 --- a/SyncClipboard/ConvertJsonClass.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SyncClipboard -{ - class ConvertJsonClass - { - public string File { get; set; } - public string Clipboard { get; set; } - } -} diff --git a/SyncClipboard/Profile.cs b/SyncClipboard/Profile.cs new file mode 100644 index 00000000..cfbad847 --- /dev/null +++ b/SyncClipboard/Profile.cs @@ -0,0 +1,84 @@ + +using System; +using System.Web.Script.Serialization; + +namespace SyncClipboard +{ + class Profile + { + public enum ClipboardType { + Text, + Image + }; + + private class JsonProfile + { + public String File { get; set; } + public String Clipboard { get; set; } + public String Type { get; set; } + } + + public String FileName { get; set; } + public String Text { get; set; } + public ClipboardType Type { get; set; } + + public Profile() + { + FileName = ""; + Text = ""; + Type = ClipboardType.Text; + } + + public Profile(String jsonStr) + { + JsonProfile jsonProfile = null; + try + { + JavaScriptSerializer serializer = new JavaScriptSerializer(); + jsonProfile = serializer.Deserialize(jsonStr); + FileName = jsonProfile.File; + Text = jsonProfile.Clipboard; + Type = StringToClipBoardType(jsonProfile.Type); + } + catch (ArgumentException) + { + Console.WriteLine("Exited profile file's format is wrong"); + FileName = ""; + Text = ""; + Type = ClipboardType.Text; + } + } + + public String ToJsonString() + { + JsonProfile jsonProfile = new JsonProfile(); + jsonProfile.File = FileName; + jsonProfile.Clipboard = Text; + jsonProfile.Type = ClipBoardTypeToString(Type); + + JavaScriptSerializer serializer = new JavaScriptSerializer(); + return serializer.Serialize(jsonProfile); + } + + static private ClipboardType StringToClipBoardType(String stringType) + { + ClipboardType type = ClipboardType.Text; + try + { + type = (ClipboardType)Enum.Parse(typeof(ClipboardType), stringType); + } + catch + { + Console.WriteLine("Profile Type is Wrong"); + throw new ArgumentException("Profile Type is Wrong"); + } + + return type; + } + + static private String ClipBoardTypeToString(ClipboardType type) + { + return Enum.GetName(typeof(ClipboardType), type); + } + } +} diff --git a/SyncClipboard/SyncClipboard.csproj b/SyncClipboard/SyncClipboard.csproj index 5e56b576..3982f1e4 100644 --- a/SyncClipboard/SyncClipboard.csproj +++ b/SyncClipboard/SyncClipboard.csproj @@ -68,11 +68,11 @@ - Component + diff --git a/SyncClipboard/SyncService.cs b/SyncClipboard/SyncService.cs index 052b0298..01ffd099 100644 --- a/SyncClipboard/SyncService.cs +++ b/SyncClipboard/SyncService.cs @@ -96,26 +96,18 @@ private void PullFromRemote() errorTimes = this.pullTimeoutTimes = 0; StreamReader objStrmReader = new StreamReader(httpWebResponse.GetResponseStream()); String strReply = objStrmReader.ReadToEnd(); - JavaScriptSerializer serializer = new JavaScriptSerializer(); - ConvertJsonClass p1=null; - try - { - p1 = serializer.Deserialize(strReply); - } - catch - { - return; - } - if (p1 != null && p1.Clipboard != this.oldString) + Profile profile = new Profile(strReply); + + if (profile.Text != this.oldString) { if (this.isFirstTime) { this.isFirstTime = false; - this.oldString = p1.Clipboard; + this.oldString = profile.Text; return; } - Clipboard.SetData(DataFormats.Text, p1.Clipboard); - this.oldString = p1.Clipboard; + Clipboard.SetData(DataFormats.Text, profile.Text); + this.oldString = profile.Text; this.mainController.setLog(true, false, "剪切板同步成功", this.SafeMessage(oldString), null, "info"); } else @@ -130,7 +122,9 @@ private HttpWebResponse GetPullResponse(String url, String auth) HttpWebResponse httpWebResponse = null; try { + Console.WriteLine("pull start " + DateTime.Now.ToString()); httpWebResponse = HttpWebResponseUtility.CreateGetHttpResponse(url, Config.TimeOut, null, auth, null); + Console.WriteLine("pull end " + DateTime.Now.ToString()); if (this.isStatusError || this.isTimeOut) { this.mainController.setLog(true, true, "连接服务器成功", "正在同步", "正在同步", "info"); @@ -170,6 +164,7 @@ private HttpWebResponse GetPullResponse(String url, String auth) } public void PushLoop() { + Console.WriteLine("Push start "+ DateTime.Now.ToString()); IDataObject ClipboardData = Clipboard.GetDataObject(); if (!ClipboardData.GetDataPresent(DataFormats.Text) && !ClipboardData.GetDataPresent(DataFormats.Bitmap)) { @@ -197,28 +192,30 @@ public void PushLoop() { continue; } + Console.WriteLine("Push end " + DateTime.Now.ToString()); return; } this.mainController.setLog(true, false, this.pushErrorMessage, "未同步:" + this.SafeMessage(str), null, "erro"); } public void PushToRemote(String str, bool isImage) { - ConvertJsonClass convertJson = new ConvertJsonClass(); - convertJson.File = ""; + Profile profile = new Profile(); if(isImage) { - convertJson.File = "image"; + profile.Type = Profile.ClipboardType.Image; + } + else + { + profile.Type = Profile.ClipboardType.Text; + profile.Text = str; } - convertJson.Clipboard = str; - JavaScriptSerializer serializer = new JavaScriptSerializer(); - string jsonString = serializer.Serialize(convertJson); String url = Config.GetProfileUrl(); String auth = "Authorization: Basic " + Config.Auth; HttpWebResponse httpWebResponse = null; try { - httpWebResponse = HttpWebResponseUtility.CreatePutHttpResponse(url, jsonString, Config.TimeOut, null, auth, null, null); + httpWebResponse = HttpWebResponseUtility.CreatePutHttpResponse(url, profile.ToJsonString(), Config.TimeOut, null, auth, null, null); } catch(Exception ex) { diff --git a/SyncClipboard/UpdateChecker.cs b/SyncClipboard/UpdateChecker.cs index e704e161..049e96e5 100644 --- a/SyncClipboard/UpdateChecker.cs +++ b/SyncClipboard/UpdateChecker.cs @@ -12,7 +12,7 @@ namespace SyncClipboard { class UpdateChecker { - public const string Version = "1.1.1"; + public const string Version = "1.1.2"; public const string UpdateUrl = "https://api.github.com/repos/Jeric-X/SyncClipboard/releases/latest"; public const string ReleaseUrl = "https://github.com/Jeric-X/SyncClipboard/releases/latest"; diff --git a/SyncClipboard/plan.txt b/SyncClipboard/plan.txt deleted file mode 100644 index 5f282702..00000000 --- a/SyncClipboard/plan.txt +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/plan.md b/plan.md new file mode 100644 index 00000000..38528f8d --- /dev/null +++ b/plan.md @@ -0,0 +1,8 @@ +## feature +- [ ] 添加处于上传/下载过程的图标变化 +- [x] win上传图片 +- [ ] win下载图片 + +## clean code +- 资源回收排查 +- 重构 \ No newline at end of file