mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
监视脚本文件夹。
This commit is contained in:
parent
858365f530
commit
21dcdfc1c0
@ -20,7 +20,7 @@ Supported Languages: 中文 / [繁體中文](README-tw.md) / [English](README-en
|
||||
7. `选择模式`由状态栏移动到`选项`菜单中。
|
||||
8. 修复`点击场景添加模型`,添加过程中不出现模型预览bug。
|
||||
9. `app.editor.scripts`由`Object`改为`Array`,不会对以前的场景造成影响。
|
||||
10. 场景脚本第三方编辑器支持,场景中创建的脚本自动同步到`SceneScript`文件夹中。
|
||||
10. 场景脚本第三方编辑器支持,场景中创建的脚本自动同步到`SceneScript`文件夹中。(未完成)
|
||||
|
||||
## v0.4.4更新【[更新日志](docs-dev/update/UpdateLog.md)】
|
||||
|
||||
|
||||
41
ShadowEditor.Server/Remote/RemoteHelper.cs
Normal file
41
ShadowEditor.Server/Remote/RemoteHelper.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace ShadowEditor.Server.Remote
|
||||
{
|
||||
/// <summary>
|
||||
/// 远程编辑帮助函数
|
||||
/// </summary>
|
||||
public class RemoteHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取远程编辑临时路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetRemotePath()
|
||||
{
|
||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (path.EndsWith("\\"))
|
||||
{
|
||||
path = path.Substring(0, path.Length - 1);
|
||||
}
|
||||
|
||||
var paths = path.Split('\\').ToList();
|
||||
paths.RemoveAt(paths.Count - 1);
|
||||
paths.Add("SceneScript");
|
||||
|
||||
path = string.Join("\\", paths);
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,9 @@ namespace ShadowEditor.Server.Remote
|
||||
{
|
||||
// see: https://github.com/jjrdk/websocket-sharp
|
||||
webSocketServer = new WebSocketServer(null, ConfigHelper.WebSocketServerPort);
|
||||
webSocketServer.AddWebSocketService<SocketServer>("/RemoteEdit");
|
||||
|
||||
webSocketServer.AddWebSocketService<RemoteSocket>("/RemoteEdit");
|
||||
|
||||
webSocketServer.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -8,46 +8,95 @@ using System.Web;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
using ShadowEditor.Model.Script;
|
||||
using ShadowEditor.Server.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ShadowEditor.Server.Remote
|
||||
{
|
||||
/// <summary>
|
||||
/// Socket服务端
|
||||
/// Remote Socket
|
||||
/// </summary>
|
||||
/// <see cref="https://github.com/jjrdk/websocket-sharp"/>
|
||||
public class SocketServer : WebSocketBehavior
|
||||
public class RemoteSocket : WebSocketBehavior
|
||||
{
|
||||
private string rootPath = RemoteHelper.GetRemotePath();
|
||||
|
||||
public RemoteSocket() : base()
|
||||
{
|
||||
var path = RemoteHelper.GetRemotePath();
|
||||
try
|
||||
{
|
||||
var watcher = new FileSystemWatcher(path);
|
||||
watcher.IncludeSubdirectories = true;
|
||||
watcher.Changed += OnFileChanged;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var log = LogHelper.GetLogger(this.GetType());
|
||||
log.Error("Create FileSystemWatcher failed.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected override Task OnOpen()
|
||||
{
|
||||
var log = LogHelper.GetLogger(this.GetType());
|
||||
log.Info("Socket open.");
|
||||
return base.OnOpen();
|
||||
}
|
||||
|
||||
protected override Task OnMessage(MessageEventArgs e)
|
||||
{
|
||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (path.EndsWith("\\"))
|
||||
{
|
||||
path = path.Substring(0, path.Length - 1);
|
||||
}
|
||||
|
||||
var paths = path.Split('\\').ToList();
|
||||
paths.RemoveAt(paths.Count - 1);
|
||||
paths.Add("SceneScript");
|
||||
|
||||
path = string.Join("\\", paths);
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
var list = GetScripts(e.Data);
|
||||
|
||||
DeleteScripts(path, true);
|
||||
DeleteScripts(rootPath, true);
|
||||
|
||||
CreateScripts("", path, list);
|
||||
CreateScripts("", rootPath, list);
|
||||
|
||||
Send(JsonConvert.SerializeObject(new
|
||||
{
|
||||
Code = 200,
|
||||
Msg = "Send Successfully!",
|
||||
Type = "Response"
|
||||
}));
|
||||
|
||||
Send("Hello, world!");
|
||||
return base.OnMessage(e);
|
||||
}
|
||||
|
||||
protected override Task OnClose(CloseEventArgs e)
|
||||
{
|
||||
var log = LogHelper.GetLogger(this.GetType());
|
||||
log.Warn("Socket close.");
|
||||
return base.OnClose(e);
|
||||
}
|
||||
|
||||
protected override Task OnError(WebSocketSharp.ErrorEventArgs e)
|
||||
{
|
||||
var log = LogHelper.GetLogger(this.GetType());
|
||||
log.Error(e.Message, e.Exception);
|
||||
return base.OnError(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 远程编辑文件发生改变
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public void OnFileChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
var list = new List<ScriptModel>();
|
||||
|
||||
TraverseFolder(rootPath, list);
|
||||
|
||||
Send(JsonConvert.SerializeObject(new
|
||||
{
|
||||
Code = 200,
|
||||
Msg = "Send Successfully!",
|
||||
Type = "Response"
|
||||
}));
|
||||
}
|
||||
|
||||
#region 场景脚本改变更新SceneScript文件夹
|
||||
private List<ScriptModel> GetScripts(Stream stream)
|
||||
{
|
||||
var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
@ -156,5 +205,23 @@ namespace ShadowEditor.Server.Remote
|
||||
|
||||
return extension;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SceneScript文件夹改变更新场景脚本
|
||||
public void TraverseFolder(string path, List<ScriptModel> scripts)
|
||||
{
|
||||
var directories = Directory.GetDirectories(path);
|
||||
var files = Directory.GetFiles(path);
|
||||
|
||||
foreach (var i in directories)
|
||||
{
|
||||
|
||||
}
|
||||
foreach (var i in files)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -216,8 +216,9 @@
|
||||
<Compile Include="Helpers\ZipHelper.cs" />
|
||||
<Compile Include="OperatingAuthority.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Remote\RemoteHelper.cs" />
|
||||
<Compile Include="Remote\RemoteServer.cs" />
|
||||
<Compile Include="Remote\SocketServer.cs" />
|
||||
<Compile Include="Remote\RemoteSocket.cs" />
|
||||
<Compile Include="Result.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user