Răsfoiți Sursa

增加Rsync同步配置工具

tanghai 9 ani în urmă
părinte
comite
afdbb776d4

+ 0 - 0
Tools/cwRsync/exclude.txt → Config/Rsync/exclude.txt


+ 1 - 0
Config/Rsync/rsync.secrets

@@ -0,0 +1 @@
+1234567890

+ 1 - 0
Config/Rsync/rsyncConfig.txt

@@ -0,0 +1 @@
+{ "_t" : "RsyncConfig", "Host" : "192.168.12.188", "Account" : "tanghai", "Password" : "1234567890", "RelativePath" : "Source/Egametang", "Exclude" : [".git/", "Log/", "Tools/", "Server/Bin/", "Server/packages/", "Server/Temp/", "Server/Server.sdf", "Unity/Library/", "Unity/Temp/", "*/obj"] }

+ 2 - 4
Tools/cwRsync/rsyncd.conf → Config/Rsync/rsyncd.conf

@@ -1,13 +1,11 @@
 uid = root
 gid = root
-#strict modes = no
 use chroot = no
 max connections = 100
 read only = no
 write only = no
-log file=/var/log/rsyncd.log
-# Remote sync configuration module
-[Tanghai]
+log file =/var/log/rsyncd.log
+[Upload]
 path = /home/tanghai/
 auth users = tanghai
 secrets file = /etc/rsyncd.secrets

+ 1 - 0
Config/Rsync/rsyncd.secrets

@@ -0,0 +1 @@
+tanghai:1234567890

+ 0 - 1
Tools/cwRsync/rsync.secrets

@@ -1 +0,0 @@
-123456

+ 13 - 0
Unity/Assets/Editor/RsyncEditor/RsyncConfig.cs

@@ -0,0 +1,13 @@
+using System.Collections.Generic;
+
+namespace MyEditor
+{
+	public class RsyncConfig
+	{
+		public string Host = "";
+		public string Account = "";
+		public string Password = "";
+		public string RelativePath = "";
+		public List<string> Exclude = new List<string>();
+	}
+}

+ 12 - 0
Unity/Assets/Editor/RsyncEditor/RsyncConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 09fcb878a3792c84fb09f0c0f1ef2572
+timeCreated: 1477277139
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 100 - 12
Unity/Assets/Editor/RsyncEditor/RsyncEditor.cs

@@ -1,23 +1,111 @@
-using System;
-using System.Diagnostics;
+using System.Diagnostics;
+using System.IO;
 using Base;
 using UnityEditor;
+using UnityEngine;
 
 namespace MyEditor
 {
 	public class RsyncEditor : EditorWindow
 	{
-		[MenuItem("Tools/同步到Linux")]
-		private static void ShowUnDisposeObjects()
+		private const string ConfigFile = @"..\Config\Rsync\rsyncConfig.txt";
+		private RsyncConfig rsyncConfig;
+		private bool isFold = true;
+
+		[MenuItem("Tools/Rsync同步")]
+		private static void ShowWindow()
+		{
+			GetWindow(typeof(RsyncEditor));
+		}
+
+		[MenuItem("Tools/Rsync同步")]
+		private static void ShowTool()
+		{
+			GetWindow(typeof(RsyncEditor));
+		}
+
+		private void OnEnable()
+		{
+			if (!File.Exists(ConfigFile))
+			{
+				this.rsyncConfig = new RsyncConfig();
+				return;
+			}
+			string s = File.ReadAllText(ConfigFile);
+			this.rsyncConfig = MongoHelper.FromJson<RsyncConfig>(s);
+		}
+
+		private void OnGUI()
 		{
-			ProcessStartInfo startInfo = new ProcessStartInfo();
-			startInfo.FileName = @"Tools\cwRsync\rsync.exe";
-			startInfo.Arguments = "-vzrtopg --password-file=./Tools/cwRsync/rsync.secrets --exclude-from=./Tools/cwRsync/exclude.txt --delete ./ tanghai@192.168.1.134::Tanghai/Source/Egametang --chmod=ugo=rwX";
-			startInfo.UseShellExecute = true;
-			startInfo.WorkingDirectory = @"..\";
-			Process p = Process.Start(startInfo);
-			p.WaitForExit();
-			Log.Info("同步完成!");
+			rsyncConfig.Host = EditorGUILayout.TextField("服务器地址", rsyncConfig.Host);
+			rsyncConfig.Account = EditorGUILayout.TextField("账号(必须是Linux已有的账号)", rsyncConfig.Account);
+			rsyncConfig.Password = EditorGUILayout.TextField("密码", rsyncConfig.Password);
+			rsyncConfig.RelativePath = EditorGUILayout.TextField("相对路径", rsyncConfig.RelativePath);
+
+			if (GUILayout.Button("添加排除项目"))
+			{
+				this.rsyncConfig.Exclude.Add("");
+			}
+			this.isFold = EditorGUILayout.Foldout(isFold, $"排除列表:");
+
+			if (!this.isFold)
+			{
+				for (int i = 0; i < this.rsyncConfig.Exclude.Count; ++i)
+				{
+					GUILayout.BeginHorizontal();
+					this.rsyncConfig.Exclude[i] = EditorGUILayout.TextField(this.rsyncConfig.Exclude[i]);
+					if (GUILayout.Button("删除"))
+					{
+						this.rsyncConfig.Exclude.RemoveAt(i);
+						break;
+					}
+					GUILayout.EndHorizontal();
+				}
+			}
+
+			if (GUILayout.Button("保存"))
+			{
+				File.WriteAllText(ConfigFile, MongoHelper.ToJson(this.rsyncConfig));
+				using (StreamWriter sw = new StreamWriter(new FileStream(@"..\Config\Rsync\rsync.secrets", FileMode.Create)))
+				{
+					foreach (string s in this.rsyncConfig.Exclude)
+					{
+						sw.Write(s + "\n");
+					}
+				}
+
+				File.WriteAllText($@"..\Config\Rsync\rsync.secrets", this.rsyncConfig.Password);
+				File.WriteAllText($@"..\Config\Rsync\rsyncd.secrets", $"{this.rsyncConfig.Account}:{this.rsyncConfig.Password}");
+
+				string rsyncdConf =
+					"uid = root\n" +
+					"gid = root\n" +
+					"use chroot = no\n" +
+					"max connections = 100\n" +
+					"read only = no\n" +
+					"write only = no\n" +
+					"log file =/var/log/rsyncd.log\n" +
+					"[Upload]\n" +
+					$"path = /home/{this.rsyncConfig.Account}/\n" +
+					$"auth users = {this.rsyncConfig.Account}\n" +
+					"secrets file = /etc/rsyncd.secrets\n" +
+					"list = yes";
+				File.WriteAllText($@"..\Config\Rsync\rsyncd.conf", rsyncdConf);
+			}
+
+			if (GUILayout.Button("同步"))
+			{
+				string arguments = $"-vzrtopg --password-file=./Config/Rsync/rsync.secrets --exclude-from=./Config/Rsync/exclude.txt --delete ./ {this.rsyncConfig.Account}@{this.rsyncConfig.Host}::Upload/{this.rsyncConfig.RelativePath} --chmod=ugo=rwX";
+				Log.Debug(arguments);
+				ProcessStartInfo startInfo = new ProcessStartInfo();
+				startInfo.FileName = @".\Tools\cwRsync\rsync.exe";
+				startInfo.Arguments = arguments;
+				startInfo.UseShellExecute = true;
+				startInfo.WorkingDirectory = @"..\";
+				Process p = Process.Start(startInfo);
+				p.WaitForExit();
+				Log.Info("同步完成!");
+			}
 		}
 	}
 }

+ 9 - 0
Unity/Assets/Editor/ServerCommandLineEditor/Component.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 24f0b40b39c2f954d9e5e63bbb17f3d6
+folderAsset: yes
+timeCreated: 1476673759
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Unity.CSharp.Editor.csproj

@@ -116,6 +116,7 @@
     <Compile Include="Assets\Editor\EditorInit.cs" />
     <Compile Include="Assets\Editor\ObjectManagerToolsEditor\ObjectManagerToolsWindow.cs" />
     <Compile Include="Assets\Editor\ReferenceCollectorEditor\ReferenceCollectorEditor.cs" />
+    <Compile Include="Assets\Editor\RsyncEditor\RsyncConfig.cs" />
     <Compile Include="Assets\Editor\RsyncEditor\RsyncEditor.cs" />
     <Compile Include="Assets\Editor\ServerCommandLineEditor\ServerCommandLineEditor.cs" />
   </ItemGroup>