1000 lines
39 KiB
C#
1000 lines
39 KiB
C#
using ICSharpCode.SharpZipLib.Zip;
|
||
using Kirurobo;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using RenderHeads.Media.AVProMovieCapture;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using TMPro;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using VRS.Util;
|
||
using static MainCanvasManager;
|
||
|
||
public class MenuPanel : PanelBasic
|
||
{
|
||
/// <summary>
|
||
/// 视频录制按钮
|
||
/// </summary>
|
||
public Button video_record_button;
|
||
/// <summary>
|
||
/// 查看媒体按钮
|
||
/// </summary>
|
||
public Button view_media_button;
|
||
/// <summary>
|
||
/// 导入媒体按钮
|
||
/// </summary>
|
||
public Button import_media_button;
|
||
/// <summary>
|
||
/// 重置场景按钮
|
||
/// </summary>
|
||
public Button reset_scene_button;
|
||
/// <summary>
|
||
/// 保存形象按钮
|
||
/// </summary>
|
||
public Button save_image_button;
|
||
/// <summary>
|
||
/// 提交按钮
|
||
/// </summary>
|
||
public Button submit_button;
|
||
/// <summary>
|
||
/// 暂存按钮
|
||
/// </summary>
|
||
public Button staging_button;
|
||
/// <summary>
|
||
/// 下载按钮
|
||
/// </summary>
|
||
public Button download_button;
|
||
|
||
|
||
/// <summary>
|
||
/// 文件路径
|
||
/// </summary>
|
||
public string file_path;
|
||
|
||
public TextMeshProUGUI video_record_text;
|
||
/// <summary>
|
||
/// 屏幕录制组件
|
||
/// </summary>
|
||
public CaptureFromScreen capture;
|
||
/// <summary>
|
||
/// 是否正在录制
|
||
/// </summary>
|
||
public bool isCapture;
|
||
|
||
public GameObject 录制标志obj;
|
||
/// <summary>
|
||
/// 左侧主菜单
|
||
/// </summary>
|
||
public GameObject UI_主;
|
||
/// <summary>
|
||
/// 录制按钮
|
||
/// </summary>
|
||
public GameObject UI_录;
|
||
/// <summary>
|
||
/// 视频录制按钮
|
||
/// </summary>
|
||
public GameObject 退出按钮;
|
||
/// <summary>
|
||
/// 暂存完成确认按钮
|
||
/// </summary>
|
||
public GameObject 暂存完成确认按钮;
|
||
protected override void Awake()
|
||
{
|
||
base.Awake();
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
/*
|
||
if (GameManager.current_main_menu_type == MainMenuType.自由编程 || GameManager.current_main_menu_type == MainMenuType.案例中心)
|
||
{
|
||
submit_button.gameObject.SetActive(false);
|
||
staging_button.gameObject.SetActive(false);
|
||
download_button.gameObject.SetActive(false);
|
||
}
|
||
|
||
video_record_button.onClick.AddListener(() => OnVideoRecord());
|
||
import_media_button.onClick.AddListener(() => OnImportMedia());
|
||
view_media_button.onClick.AddListener(() => OnMediaViwer());
|
||
save_image_button.onClick.AddListener(() => OnSaveImage());
|
||
submit_button.onClick.AddListener(() =>
|
||
{
|
||
MyOnSubmit();
|
||
});
|
||
reset_scene_button.onClick.AddListener(() => OnResetScene());
|
||
staging_button.onClick.AddListener(() =>
|
||
{
|
||
MyOnStaging();
|
||
});
|
||
download_button.onClick.AddListener(() =>
|
||
{
|
||
MyOnDownload();
|
||
});
|
||
*/
|
||
// OnDownload();
|
||
//ClearDirectory(CallForTest.instance.pathProject);
|
||
}
|
||
|
||
public void MyOnStaging()
|
||
{
|
||
//判断是否有文件
|
||
if (Directory.GetFiles(CallForTest.instance.pathProject).Length > 0 || Directory.GetDirectories(CallForTest.instance.pathProject).Length > 0)
|
||
{
|
||
MainCanvasManager.confirm_panel.OnPopup("是否暂存当前工作目录?", "", _callback: isok =>
|
||
{
|
||
if (isok)
|
||
{
|
||
OnStaging("暂存");
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
MainCanvasManager.confirm_panel.OnPopup("未打开代码工程,无需暂存", "");
|
||
}
|
||
}
|
||
|
||
public void MyOnDownload()
|
||
{
|
||
MainCanvasManager.confirm_panel.OnPopup("此操作将会覆盖当前工作目录文件,是否要下载上次暂存的代码?", "", _callback: isok =>
|
||
{
|
||
if (isok)
|
||
{
|
||
OnDownload();
|
||
}
|
||
});
|
||
}
|
||
|
||
public void MyOnSubmit()
|
||
{
|
||
MainCanvasManager.confirm_panel.OnPopup("是否提交当前任务?", "", _callback: isok =>
|
||
{
|
||
if (isok)
|
||
{
|
||
OnSubmit();
|
||
}
|
||
});
|
||
}
|
||
|
||
public void OnVideoRecord()
|
||
{
|
||
if (!isCapture)
|
||
{
|
||
StartVideoRecord();
|
||
}
|
||
else
|
||
{
|
||
StopVideoRecord();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开始录制
|
||
/// </summary>
|
||
public void StartVideoRecord()
|
||
{
|
||
Debug.Log(111);
|
||
if (capture != null)
|
||
{
|
||
capture.OutputFolderPath = CallForTest.instance.pathTaskFile;
|
||
capture.FilenamePrefix = "任务";
|
||
capture.AppendFilenameTimestamp = false;
|
||
|
||
录制标志obj.SetActive(true);
|
||
isCapture = true;
|
||
//这里暂时关掉提示录制得功能
|
||
/*
|
||
//提示是否开始录制
|
||
MainCanvasManager.confirm_panel.OnPopup("录制确认", "是否开始录屏?", "提示", result =>
|
||
{
|
||
if (result)
|
||
{
|
||
isCapture = true;
|
||
capture.StartCapture();
|
||
Debug.Log("开始录制");
|
||
video_record_text.text = "结束录制";
|
||
video_record_text.color = Color.red;
|
||
录制标志obj.SetActive(true);
|
||
}
|
||
});
|
||
*/
|
||
|
||
capture.StartCapture();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 结束录制
|
||
/// </summary>
|
||
public void StopVideoRecord()
|
||
{
|
||
if (capture != null)
|
||
{
|
||
isCapture = false;
|
||
capture.StopCapture();
|
||
Debug.Log("停止录制");
|
||
video_record_text.text = "开始录制";
|
||
video_record_text.color = Color.white;
|
||
录制标志obj.SetActive(false);
|
||
|
||
|
||
//这里可以直接打开录制视频所在路径,但是当前功能不需要所以这里禁用掉
|
||
/*
|
||
//提示录制结束,打开所在文件路径
|
||
MainCanvasManager.confirm_panel.OnPopup("录制完成", "录制完成,是否打开文件路径?", "提示", result =>
|
||
{
|
||
if (result)
|
||
{
|
||
Utils.ShowInExplorer(CaptureBase.LastFileSaved);
|
||
}
|
||
});
|
||
*/
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导入媒体
|
||
/// </summary>
|
||
public void OnImportMedia()
|
||
{
|
||
//Path = base.OpenProject();
|
||
//OpenSingleFile();
|
||
//Debug.Log(file_path);
|
||
var _res = OpenFile.OpenFileWin();
|
||
if (_res != null)
|
||
{
|
||
//是否有新增
|
||
bool _add_new = false;
|
||
//是否仅有音频
|
||
bool _only_audio;
|
||
//文件类型
|
||
string _type;
|
||
if (_res.Length == 1)
|
||
{
|
||
_type = _res[0].Split('.')[^1];
|
||
//_type = _res[0].Split('.')[_res[0].Split('.').Length - 1];
|
||
_add_new |= media_viwer_panel.Init(_type, _res[0].Split('\\')[^1], _res[0]);
|
||
//_add_new |= media_viwer_panel.Init(_type, _res[0].Split('\\')[_res[0].Split('\\').Length - 1], _res[0]);
|
||
_only_audio = _type == "mp3";
|
||
}
|
||
else
|
||
{
|
||
_only_audio = true;
|
||
var _path = _res[0];
|
||
for (int i = 1; i < _res.Length; i++)
|
||
{
|
||
_type = _res[i].Split('.')[1];
|
||
_add_new |= media_viwer_panel.Init(_res[i].Split('.')[1], _res[i], _path + "\\" + _res[i]);
|
||
_only_audio &= _type == "mp3";
|
||
}
|
||
}
|
||
|
||
if (_add_new)
|
||
{
|
||
//如果有新增,则打开媒体查看面板
|
||
media_viwer_panel.OnPopup();
|
||
//切换到对应标签,若都有,则显示视频,只有音频,显示音频
|
||
//todo
|
||
if (_only_audio)
|
||
{
|
||
media_viwer_panel.audio_files_button.isOn = true;
|
||
media_viwer_panel.OnVideoFiles(false);
|
||
media_viwer_panel.OnAudioFiles(true);
|
||
}
|
||
else
|
||
{
|
||
media_viwer_panel.video_files_button.isOn = true;
|
||
media_viwer_panel.OnVideoFiles(true);
|
||
media_viwer_panel.OnAudioFiles(false);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查看媒体资源
|
||
/// </summary>
|
||
public void OnMediaViwer()
|
||
{
|
||
media_viwer_panel.OnPopup();
|
||
}
|
||
public void OnSaveImage()
|
||
{
|
||
//Instantiate(OneImage, Canvas);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 原提交部分
|
||
/// </summary>
|
||
#region
|
||
/// <summary>
|
||
/// 提交按钮
|
||
/// </summary>
|
||
public void OnSubmit()
|
||
{
|
||
buttonFunctionAdd.Instance.开始项目.kill();
|
||
ConsolePanel.ConsoleOutput("开始提交任务数据", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交任务数据");
|
||
//任务分数回传
|
||
Task_Setp_Back.instance.TaskInfoDataBack(task_panel.task_item_data, ScoreManager.Instance.total_score, (result, msg) =>
|
||
{
|
||
if (result)
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务数据完成", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务数据完成");
|
||
if (File.Exists(CallForTest.instance.pathTaskFile + "/任务.png"))
|
||
{
|
||
//有截图,回传任务截图
|
||
SubmitJT();
|
||
}
|
||
else if(File.Exists(CallForTest.instance.pathTaskFile + "/任务.mp4"))
|
||
{
|
||
//没截图,回传任务录屏
|
||
ConsolePanel.ConsoleOutput("无任务截图提交", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无任务截图提交");
|
||
SubmitLP();
|
||
}
|
||
else
|
||
{
|
||
//也没录屏,回传步骤截图
|
||
ConsolePanel.ConsoleOutput("无任务截图提交", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无任务截图提交");
|
||
ConsolePanel.ConsoleOutput("无任务录屏提交", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无任务录屏提交");
|
||
SubmitStepJT();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务分数失败", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务分数失败");
|
||
confirm_panel.OnPopup("提交任务分数失败", msg);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 提交任务截图
|
||
/// </summary>
|
||
private void SubmitJT()
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始提交任务截图", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交任务截图");
|
||
Task_Setp_Back.instance.TaskPictureBack(task_panel.task_item_data, File.ReadAllBytes(CallForTest.instance.pathTaskFile + "/任务.png"), ConsolePanel.ConsoleOutput("0%", "log"), (isok1, msg1) =>
|
||
{
|
||
if (isok1)
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务截图完成", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务截图完成");
|
||
if (File.Exists(CallForTest.instance.pathTaskFile + "/任务.mp4"))
|
||
{
|
||
//有录屏,回传录屏
|
||
SubmitLP();
|
||
}
|
||
else
|
||
{
|
||
//没录屏,回传步骤截图
|
||
ConsolePanel.ConsoleOutput("无任务录屏提交", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无任务录屏提交");
|
||
SubmitStepJT();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务截图失败", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务截图失败");
|
||
confirm_panel.OnPopup("提交任务截图失败", msg1);
|
||
}
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交任务录屏
|
||
/// </summary>
|
||
private void SubmitLP()
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始提交任务录屏", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交任务录屏");
|
||
//上传minio
|
||
UpLoadFileToMinio(CallForTest.instance.pathTaskFile + "/任务.mp4", (isok0, downPath) =>
|
||
{
|
||
if (isok0)
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务录屏完成", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务录屏完成");
|
||
ConsolePanel.ConsoleOutput("开始同步云端数据", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始同步云端数据");
|
||
//提交数据
|
||
Task_Setp_Back.instance.TaskVideoBack(task_panel.task_item_data, downPath, (isok1, msg1) =>
|
||
{
|
||
if (isok1)
|
||
{
|
||
ConsolePanel.ConsoleOutput("同步云端数据完成", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "同步云端数据完成");
|
||
//回传步骤截图
|
||
SubmitStepJT();
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("同步云端数据失败", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "同步云端数据失败");
|
||
confirm_panel.OnPopup("同步云端数据失败", msg1);
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交任务录屏失败", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务录屏失败");
|
||
confirm_panel.OnPopup("提交任务录屏失败", "");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交任务录屏失败");
|
||
}
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交步骤截图
|
||
/// </summary>
|
||
private void SubmitStepJT()
|
||
{
|
||
List<string> files= new List<string>();
|
||
Directory.GetFiles(CallForTest.instance.pathTaskFile).ToList().ForEach(a =>
|
||
{
|
||
string filename= Path.GetFileName(a);
|
||
if(filename.StartsWith("步骤_"))
|
||
{
|
||
files.Add(filename);
|
||
}
|
||
});
|
||
|
||
if(files.Count>0)
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始提交步骤截图", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交步骤截图");
|
||
SubmOneStepJT(files, 0);
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("无步骤截图提交", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无步骤截图提交");
|
||
//暂存文件
|
||
TijiaoFile();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 上传单个步骤截图
|
||
/// </summary>
|
||
private void SubmOneStepJT(List<string> files, int index)
|
||
{
|
||
if (index < files.Count)
|
||
{
|
||
string tmpFileName = files[index];
|
||
TaskStep step = task_panel.task_item_data.task_steplist.Find(a => "步骤_" + a.stepName + ".png" == tmpFileName);
|
||
if (step != null)
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始提交步骤截图:" + tmpFileName, "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交步骤截图");
|
||
Task_Setp_Back.instance.StepPictureBack(step, tmpFileName, File.ReadAllBytes(CallForTest.instance.pathTaskFile + "/" + tmpFileName), ConsolePanel.ConsoleOutput("0%", "log"), (isok, msg) =>
|
||
{
|
||
if (isok)
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交成功:" + tmpFileName, "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交成功");
|
||
//提交下一个
|
||
SubmOneStepJT(files, index + 1);
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("提交步骤截图失败" + tmpFileName, "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交步骤截图失败");
|
||
confirm_panel.OnPopup("提交步骤截图失败" + tmpFileName, msg);
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
//找不到此步骤,提交下一个
|
||
Debug.Log("找不到图片对应的步骤");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "找不到图片对应的步骤");
|
||
SubmOneStepJT(files, index + 1);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("结束步骤截图提交");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "步骤截图全部提交完成");
|
||
ConsolePanel.ConsoleOutput("步骤截图全部提交完成", "log");
|
||
//提交文件
|
||
TijiaoFile();
|
||
}
|
||
}
|
||
|
||
|
||
private void TijiaoFile()
|
||
{
|
||
//判断是否有文件
|
||
if (Directory.GetFiles(CallForTest.instance.pathProject).Length > 0 || Directory.GetDirectories(CallForTest.instance.pathProject).Length > 0)
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始提交代码工程", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始提交代码工程");
|
||
OnStaging("提交");
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("无代码工程可提交", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "无代码工程可提交");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "提交完成");
|
||
confirm_panel.OnPopup("提交完成", "可以退出房间了");
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 上传文件到minio地址
|
||
/// </summary>
|
||
private void UpLoadFileToMinio(string filePath, Action<bool, string> callback)
|
||
{
|
||
//md5值
|
||
FileStream file = new FileStream(filePath, FileMode.Open);
|
||
long length = file.Length;
|
||
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||
byte[] retVal = md5.ComputeHash(file);
|
||
file.Close();
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int i = 0; i < retVal.Length; i++)
|
||
{
|
||
sb.Append(retVal[i].ToString("x2"));
|
||
}
|
||
string md5value = sb.ToString();
|
||
Debug.Log("上传文件:" + Path.GetFileName(filePath) + " MD5:" + md5value);
|
||
string url = InterfaceManager.IdAddress + ":8080/minio/tasks/upload/" + md5value + "?totalSize=" + length + "&fileName=" + Path.GetFileName(filePath) + "&bucketName=ictcomcache";
|
||
Debug.Log("获取上传地址:" + url);
|
||
//获取文件上传地址
|
||
ConsolePanel.ConsoleOutput("获取文件上传地址", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "获取文件上传地址");
|
||
|
||
StartCoroutine(Task_Setp_Back.Get(url, false, (isok, result) =>
|
||
{
|
||
if (isok)
|
||
{
|
||
if (!string.IsNullOrEmpty(result))
|
||
{
|
||
JObject jo = JObject.Parse(result);
|
||
Debug.Log(result);
|
||
if (jo["code"].ToObject<int>() == 200)
|
||
{
|
||
string presignedUrl = jo["data"]["taskRecord"]["presignedUrl"].ToString();
|
||
string downloadPath = jo["data"]["path"].ToString();
|
||
Debug.Log("presignedUrl:" + presignedUrl);
|
||
Debug.Log("downloadPath:" + downloadPath);
|
||
|
||
if (jo["data"]["finished"].ToObject<bool>() == false)
|
||
{
|
||
//未上传
|
||
ConsolePanel.ConsoleOutput("开始上传", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "开始上传");
|
||
//上传文件
|
||
StartCoroutine(Task_Setp_Back.Put(presignedUrl, File.ReadAllBytes(filePath), ConsolePanel.ConsoleOutput("0%", "log"), (isok1, result1) =>
|
||
{
|
||
if (isok1)
|
||
{
|
||
ConsolePanel.ConsoleOutput("上传完成100%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "上传完成100%");
|
||
Debug.Log("文件上传成功");
|
||
callback(true, downloadPath);
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("暂存失败"+ result1, "log");
|
||
//confirm_panel.OnPopup("暂存失败", result1);
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "暂存失败");
|
||
callback(false, null);
|
||
}
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
//文件md5重复
|
||
Debug.Log("文件已存在,无需上传");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "文件已存在无需上传");
|
||
callback(true, downloadPath);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//confirm_panel.OnPopup("暂存失败", jo["msg"].ToString());
|
||
ConsolePanel.ConsoleOutput("暂存失败"+ jo["msg"].ToString(), "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "暂存失败");
|
||
callback(false, null);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("暂存失败", "log");
|
||
//confirm_panel.OnPopup("暂存失败", "");
|
||
// WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "暂存失败");
|
||
callback(false, null);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("暂存失败"+ result,"log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataSunmit, "暂存失败");
|
||
callback(false, null);
|
||
}
|
||
}));
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 重置场景
|
||
/// </summary>
|
||
public void OnResetScene()
|
||
{
|
||
on_reset_scene?.Invoke();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 暂存
|
||
/// </summary>
|
||
#region
|
||
public void OnStaging(string actionMsg)
|
||
{
|
||
|
||
//zip压缩包
|
||
string outpath = CallForTest.instance.pathCache+ "/TmpCode.zip";
|
||
string inpath = CallForTest.instance.pathProject;
|
||
|
||
if (File.Exists(outpath))
|
||
{
|
||
File.Delete(outpath);
|
||
}
|
||
|
||
ConsolePanel.ConsoleOutput("开始压缩0%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.TemporaryStorage,"开始压缩0%");
|
||
System.IO.Compression.ZipFile.CreateFromDirectory(inpath, outpath);
|
||
//Zip zip = new Zip();
|
||
//Encoding gbk = Encoding.GetEncoding("GBK");
|
||
//ZipStrings.CodePage = gbk.CodePage;
|
||
//if (zip.ZipFileDictory(inpath, outpath))
|
||
{
|
||
ConsolePanel.ConsoleOutput("压缩完成100%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.TemporaryStorage, "压缩完成100%");
|
||
Debug.Log("压缩完成100%");
|
||
|
||
UpLoadFileToMinio(outpath, (isok0, downPath) =>
|
||
{
|
||
if (isok0)
|
||
{
|
||
//更新数据库
|
||
string url2 = InterfaceManager.IdAddress + ":8080/component/userCodeingInfo";
|
||
ConsolePanel.ConsoleOutput("开始更新云端数据", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.TemporaryStorage, "开始更新云端数据");
|
||
if (CallForTest.instance.saveInfo == null)
|
||
{
|
||
//没有暂存过
|
||
MyTmpSaveInfo saveInfo = new MyTmpSaveInfo();
|
||
// 暂时改动,暂时把任务id和userId删掉了
|
||
saveInfo.taskId = CallForTest.instance.currentTaskData.task_id;
|
||
saveInfo.userId = CallForTest.instance.user.userId;
|
||
saveInfo.dataType = "TmpCode.zip";
|
||
saveInfo.dataContent = downPath;
|
||
|
||
StartCoroutine(Task_Setp_Back.Post(url2, JsonConvert.SerializeObject(saveInfo), null,(isok1, result1) =>
|
||
{
|
||
if (isok1)
|
||
{
|
||
JObject jo1 = JObject.Parse(result1);
|
||
if (jo1["code"].ToObject<int>() == 200)
|
||
{
|
||
CallForTest.instance.saveInfo = saveInfo;
|
||
if (actionMsg == "提交")
|
||
{
|
||
退出按钮.SetActive(true);
|
||
退出按钮.transform.GetChild(1).GetComponent<Text>().text = "提交完成,是否退出程序";
|
||
}
|
||
else if (actionMsg == "暂存")
|
||
{
|
||
暂存完成确认按钮.SetActive(true);
|
||
暂存完成确认按钮.transform.GetChild(1).GetComponent<Text>().text = "暂存完成";
|
||
}
|
||
ConsolePanel.ConsoleOutput(actionMsg + "提交文件成功", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.TemporaryStorage, "提交成功");
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput(actionMsg+"失败"+ jo1["msg"].ToString(),"log");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput(actionMsg+ "失败" + result1,"log");
|
||
}
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
//有暂存记录
|
||
MyTmpSaveInfo saveInfo = new MyTmpSaveInfo();
|
||
saveInfo.id = CallForTest.instance.saveInfo.id;
|
||
saveInfo.taskId = CallForTest.instance.saveInfo.taskId;
|
||
saveInfo.userId = CallForTest.instance.saveInfo.userId;
|
||
saveInfo.dataType = CallForTest.instance.saveInfo.dataType;
|
||
saveInfo.dataContent = downPath;
|
||
StartCoroutine(Task_Setp_Back.Post(url2, JsonConvert.SerializeObject(saveInfo), null,(isok1, result1) =>
|
||
{
|
||
if (isok1)
|
||
{
|
||
CallForTest.instance.saveInfo.dataContent = downPath;
|
||
if (actionMsg == "提交")
|
||
{
|
||
退出按钮.SetActive(true);
|
||
退出按钮.transform.GetChild(1).GetComponent<Text>().text = "提交完成,是否退出程序";
|
||
}
|
||
else if(actionMsg == "暂存")
|
||
{
|
||
暂存完成确认按钮.SetActive(true);
|
||
暂存完成确认按钮.transform.GetChild(1).GetComponent<Text>().text = "暂存完成";
|
||
}
|
||
ConsolePanel.ConsoleOutput(actionMsg+"提交文件成功", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.TemporaryStorage, "提交成功");
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput(actionMsg+"失败"+ result1,"log");
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 下载
|
||
/// </summary>
|
||
public void OnDownload()
|
||
{
|
||
buttonFunctionAdd.Instance.开始项目.kill();
|
||
// MainCanvasManager.Instance.transform.Find("Main").transform.GetChild(0).GetChild(0).GetComponent<IDEsettingPanel>().DownLoadProject(true);
|
||
DownLoadProject();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下载当前目录
|
||
/// </summary>
|
||
public void DownLoadProject()
|
||
{
|
||
//gameObject.SetActive(true);
|
||
|
||
//先清空临时代码目录
|
||
if (GameManager.current_main_menu_type == MainMenuType.课程任务)
|
||
{
|
||
if (CallForTest.instance != null && CallForTest.instance.currentTaskData != null && CallForTest.instance.currentTaskData.programDto != null && !string.IsNullOrEmpty(CallForTest.instance.currentTaskData.programDto.programPackageFileUrl))
|
||
{
|
||
//查看是否有暂存
|
||
string url1 = InterfaceManager.IdAddress + ":8080/component/userCodeingInfo/getDetail?taskId=" + CallForTest.instance.currentTaskData.task_id + "&userId=" + CallForTest.instance.user.userId + "&dataType=TmpCode.zip";
|
||
ConsolePanel.ConsoleOutput("正在检测是否有暂存工程", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "正在检测是否有暂存工程");
|
||
StartCoroutine(InterfaceManager.Get(url1, (isok, result) =>
|
||
{
|
||
if (isok)
|
||
{
|
||
JObject jb1 = JObject.Parse(result);
|
||
if (jb1["code"].ToObject<int>() == 200)
|
||
{
|
||
if (jb1["data"].ToString()!= "")
|
||
{
|
||
//测试输出
|
||
//ConsolePanel.ConsoleOutput(jb1["data"].ToString(), "log");
|
||
//有则下载暂存工程
|
||
CallForTest.instance.saveInfo = JsonConvert.DeserializeObject<MyTmpSaveInfo>(jb1["data"].ToString());
|
||
Debug.Log(jb1);
|
||
Debug.Log(jb1["data"].ToString());
|
||
string zipurl = CallForTest.instance.saveInfo.dataContent;
|
||
if (!string.IsNullOrEmpty(zipurl))
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始下载暂存工程", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "开始下载缓存工程");
|
||
LoadPakageAndUnpackZip(zipurl, CallForTest.instance.saveInfo.dataType);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("开始下载初始代码包0%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "开始下载初始代码包0%");
|
||
//没有则下载程序包
|
||
LoadPakageAndUnpackZip(CallForTest.instance.currentTaskData.programDto.programPackageFileUrl, CallForTest.instance.currentTaskData.programDto.programPackageFileName);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("获取暂存数据失败"+ jb1["msg"].ToString(),"log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "获取暂存数据失败");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("获取暂存数据失败"+result,"log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "获取暂存数据失败");
|
||
}
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("未找到代码文件", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "未找到代码文件");
|
||
}
|
||
}
|
||
else if (GameManager.current_main_menu_type == MainMenuType.案例中心)
|
||
{
|
||
if (CallForTest.instance != null && CallForTest.instance.currentTaskData != null && CallForTest.instance.currentTaskData.programDto != null && !string.IsNullOrEmpty(CallForTest.instance.currentTaskData.programDto.programPackageFileUrl))
|
||
{
|
||
//直接下载程序包
|
||
ConsolePanel.ConsoleOutput("开始下载初始代码包0%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "开始下载初始代码包0%");
|
||
LoadPakageAndUnpackZip(CallForTest.instance.currentTaskData.programDto.programPackageFileUrl, CallForTest.instance.currentTaskData.programDto.programPackageFileName);
|
||
}
|
||
else
|
||
{
|
||
ConsolePanel.ConsoleOutput("未找到代码文件", "error");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "未找到代码文件");
|
||
}
|
||
}
|
||
|
||
//自由模式暂不提供下载代码
|
||
/*
|
||
else if (GameManager.current_main_menu_type == MainMenuType.自由编程)
|
||
{
|
||
|
||
//工程目录初始化
|
||
//UnityEngine.Debug.LogError(CallForTest.instance.pathFreeProjectRoot+"hahaha");
|
||
if (Directory.GetFiles(CallForTest.instance.pathFreeProjectRoot + "/Python").Length == 0)
|
||
File.Copy(CallForTest.instance.pathRoot + "/main.py", CallForTest.instance.pathFreeProjectRoot + "/Python/main.py", true);
|
||
ConsolePanel.ConsoleOutput("开始下载初始代码包0%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "开始下载初始代码包0%");
|
||
//File.Copy(CallForTest.instance.pathRoot + "/main.py", CallForTest.instance.pathFreeProjectRoot + "/Python/main.py", true);
|
||
//File.Copy(CallForTest.instance.pathRoot + "/main.py", CallForTest.instance.pathFreeProjectRoot + "/Python/main.py", true);
|
||
|
||
//启用按钮
|
||
//runPython.gameObject.SetActive(true);
|
||
//runJava.gameObject.SetActive(true);
|
||
//runC.gameObject.SetActive(true);
|
||
}
|
||
*/
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下载工程包,并解压到临时工程文件夹
|
||
/// </summary>
|
||
/// <param name="packageUrl"></param>
|
||
/// <param name="packageName"></param>
|
||
private void LoadPakageAndUnpackZip(string packageUrl, string packageName)
|
||
{
|
||
StartCoroutine(InterfaceManager.GetData(packageUrl, ConsolePanel.ConsoleOutput("0%", "log"), (isok2, data) =>
|
||
{
|
||
ConsolePanel.ConsoleOutput("下载完成100%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "下载完成100%");
|
||
UnityEngine.Debug.Log("下载完成:" + packageUrl);
|
||
if (isok2 && data != null)
|
||
{
|
||
ClearDirectory(CallForTest.instance.pathCache);
|
||
string zipname = CallForTest.instance.pathCache + "/" + packageName;
|
||
File.WriteAllBytes(zipname, data);
|
||
|
||
//清空临时工程目录
|
||
ClearDirectory(CallForTest.instance.pathProject);
|
||
|
||
ConsolePanel.ConsoleOutput("开始解压0%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "开始解压0%");
|
||
System.IO.Compression.ZipFile.ExtractToDirectory(zipname, CallForTest.instance.pathProject, Encoding.GetEncoding("GBK"), true);
|
||
//解压zip到目标目录
|
||
//Zip zip = new Zip();
|
||
//Encoding gbk = Encoding.GetEncoding("GBK");
|
||
//ZipStrings.CodePage = gbk.CodePage;
|
||
//zip.Extract(zipname, pathProject + "/", 2048);
|
||
ConsolePanel.ConsoleOutput("解压完成100%", "log");
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "解压完成100%");
|
||
|
||
//启用按钮
|
||
//runPython.gameObject.SetActive(CallForTest.instance.currentTaskData.programDto.programLanguage == "Python");
|
||
//runJava.gameObject.SetActive(CallForTest.instance.currentTaskData.programDto.programLanguage == "Java");
|
||
//runC.gameObject.SetActive(CallForTest.instance.currentTaskData.programDto.programLanguage == "C");
|
||
}
|
||
else
|
||
{
|
||
UnityEngine.Debug.Log("下载失败:" + packageUrl);
|
||
WebSocketServerManager.Instance.SendMessage(ToolsEventEnum.DataReading, "下载失败");
|
||
//MainCanvasManager.confirm_panel.OnPopup("下载失败" + packageUrl, "");
|
||
ConsolePanel.ConsoleOutput("下载失败"+ packageUrl, "log");
|
||
}
|
||
}));
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 清空文件夹
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
private void ClearDirectory(string path)
|
||
{
|
||
if (Directory.Exists(path))
|
||
{
|
||
Directory.GetFiles(path).ToList().ForEach(a =>
|
||
{
|
||
File.Delete(a);
|
||
});
|
||
Directory.GetDirectories(path).ToList().ForEach(a =>
|
||
{
|
||
Directory.Delete(a, true);
|
||
});
|
||
Debug.Log("已清空文件夹");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 暂存方法
|
||
/// </summary>
|
||
public void ZanCunPanel()
|
||
{
|
||
Debug.Log("暂存成功");
|
||
}
|
||
/// <summary>
|
||
/// 下载方法
|
||
/// </summary>
|
||
public void XiaZaiPanel()
|
||
{
|
||
Debug.Log("下载方法");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开windows选择路径工具
|
||
/// </summary>
|
||
private void OpenSingleFile()
|
||
{
|
||
FilePanel.Settings settings = new FilePanel.Settings();
|
||
settings.filters = new FilePanel.Filter[]
|
||
{
|
||
//new FilePanel.Filter("All files", "*"),
|
||
new FilePanel.Filter("媒体文件(*.png;*.jpg;*.jpeg;*.mp3;*.mp4;*.mov;*.avi;)", "png", "jpg", "jpeg","mp3", "mp4", "mov", "avi"),
|
||
//new FilePanel.Filter("Vidos files (*.mp4;*.mov;*.avi)", "mp4", "mov", "avi"),
|
||
//new FilePanel.Filter("Documents (*.txt;*.rtf;*.doc;*.docx)", "txt", "rtf", "doc", "docx"),
|
||
};
|
||
settings.title = "导入媒体";
|
||
settings.initialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
|
||
FilePanel.OpenFilePanel(settings, (files) =>
|
||
{
|
||
file_path = string.Join("\n", files);
|
||
});
|
||
}
|
||
}
|