Skip to content

Commit

Permalink
- change profile file's syntax
Browse files Browse the repository at this point in the history
- update ios workflow
  • Loading branch information
Jeric-X committed Sep 19, 2020
1 parent cc8c0f5 commit 1348259
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.1.2
- change profile file's syntax
- update ios workflow

v1.1.1
- fix bug

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

## 配置

Expand Down
14 changes: 0 additions & 14 deletions SyncClipboard/ConvertJsonClass.cs

This file was deleted.

84 changes: 84 additions & 0 deletions SyncClipboard/Profile.cs
Original file line number Diff line number Diff line change
@@ -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<JsonProfile>(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);
}
}
}
2 changes: 1 addition & 1 deletion SyncClipboard/SyncClipboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="ConvertJsonClass.cs" />
<Compile Include="HttpWebResponseUtility.cs" />
<Compile Include="Control\MainController.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Profile.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PushService.cs" />
Expand Down
39 changes: 18 additions & 21 deletions SyncClipboard/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConvertJsonClass>(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
Expand All @@ -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");
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion SyncClipboard/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
1 change: 0 additions & 1 deletion SyncClipboard/plan.txt

This file was deleted.

8 changes: 8 additions & 0 deletions plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## feature
- [ ] 添加处于上传/下载过程的图标变化
- [x] win上传图片
- [ ] win下载图片

## clean code
- 资源回收排查
- 重构

0 comments on commit 1348259

Please sign in to comment.