Browse Source

Merge branch 'new' of github.com:shangfengh/THUAI6 into new

tags/0.1.0
shangfengh 2 years ago
parent
commit
9b92d5f34b
14 changed files with 88 additions and 66 deletions
  1. +1
    -1
      .github/workflows/upload_deploy.yml
  2. +5
    -5
      CAPI/cpp/API/include/API.h
  3. +6
    -10
      CAPI/cpp/API/src/API.cpp
  4. +6
    -10
      CAPI/cpp/API/src/DebugAPI.cpp
  5. +3
    -3
      CAPI/python/PyAPI/AI.py
  6. +6
    -6
      CAPI/python/PyAPI/API.py
  7. +6
    -6
      CAPI/python/PyAPI/DebugAPI.py
  8. +1
    -1
      CAPI/python/PyAPI/Interface.py
  9. +0
    -2
      installer/Installer/Installer.csproj
  10. +33
    -15
      installer/Installer/Model.cs
  11. +8
    -1
      installer/Installer/ViewModel.cs
  12. +1
    -3
      installer/InstallerUpdater/InstallerUpdater.csproj
  13. +1
    -0
      installer/InstallerUpdater/MainWindow.xaml.cs
  14. +11
    -3
      installer/InstallerUpdater/Program.cs

+ 1
- 1
.github/workflows/upload_deploy.yml View File

@@ -24,7 +24,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.9'

- name: Pip Install paramiko
run: pip install paramiko


+ 5
- 5
CAPI/cpp/API/include/API.h View File

@@ -118,7 +118,7 @@ public:
[[nodiscard]] virtual std::pair<int64_t, std::string> GetMessage() = 0;

// 等待下一帧
virtual std::future<bool> Wait() = 0;
virtual bool Wait() = 0;

// 获取视野内可见的学生/捣蛋鬼的信息
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const = 0;
@@ -242,7 +242,7 @@ public:
[[nodiscard]] bool HaveMessage() override;
[[nodiscard]] std::pair<int64_t, std::string> GetMessage() override;

std::future<bool> Wait() override;
bool Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;
@@ -330,7 +330,7 @@ public:
[[nodiscard]] bool HaveMessage() override;
[[nodiscard]] std::pair<int64_t, std::string> GetMessage() override;

std::future<bool> Wait() override;
bool Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;
@@ -410,7 +410,7 @@ public:
[[nodiscard]] bool HaveMessage() override;
[[nodiscard]] std::pair<int64_t, std::string> GetMessage() override;

std::future<bool> Wait() override;
bool Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;
@@ -483,7 +483,7 @@ public:
[[nodiscard]] bool HaveMessage() override;
[[nodiscard]] std::pair<int64_t, std::string> GetMessage() override;

std::future<bool> Wait() override;
bool Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;


+ 6
- 10
CAPI/cpp/API/src/API.cpp View File

@@ -217,24 +217,20 @@ std::pair<int64_t, std::string> TrickerAPI::GetMessage()
return logic.GetMessage();
}

std::future<bool> StudentAPI::Wait()
bool StudentAPI::Wait()
{
if (logic.GetCounter() == -1)
return std::async(std::launch::async, [this]()
{ return false; });
return false;
else
return std::async(std::launch::async, [this]()
{ return logic.WaitThread(); });
return logic.WaitThread();
}

std::future<bool> TrickerAPI::Wait()
bool TrickerAPI::Wait()
{
if (logic.GetCounter() == -1)
return std::async(std::launch::async, [this]()
{ return false; });
return false;
else
return std::async(std::launch::async, [this]()
{ return logic.WaitThread(); });
return logic.WaitThread();
}

std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentAPI::GetTrickers() const


+ 6
- 10
CAPI/cpp/API/src/DebugAPI.cpp View File

@@ -403,26 +403,22 @@ std::pair<int64_t, std::string> TrickerDebugAPI::GetMessage()
return result;
}

std::future<bool> StudentDebugAPI::Wait()
bool StudentDebugAPI::Wait()
{
logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint));
if (logic.GetCounter() == -1)
return std::async(std::launch::async, []()
{ return false; });
return false;
else
return std::async(std::launch::async, [this]()
{ return logic.WaitThread(); });
return logic.WaitThread();
}

std::future<bool> TrickerDebugAPI::Wait()
bool TrickerDebugAPI::Wait()
{
logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint));
if (logic.GetCounter() == -1)
return std::async(std::launch::async, []()
{ return false; });
return false;
else
return std::async(std::launch::async, [this]()
{ return logic.WaitThread(); });
return logic.WaitThread();
}

std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentDebugAPI::GetTrickers() const


+ 3
- 3
CAPI/python/PyAPI/AI.py View File

@@ -43,7 +43,7 @@ class AI(IAI):
self.__playerID = pID

def StudentPlay(self, api: IStudentAPI) -> None:
#公共操作
# 公共操作
if self.__playerID == 0:
# 玩家0执行操作
return
@@ -56,8 +56,8 @@ class AI(IAI):
elif self.__playerID == 3:
# 玩家3执行操作
return
#可以写成if self.__playerID<2之类的写法
#公共操作
# 可以写成if self.__playerID<2之类的写法
# 公共操作
return

def TrickerPlay(self, api: ITrickerAPI) -> None:


+ 6
- 6
CAPI/python/PyAPI/API.py View File

@@ -79,11 +79,11 @@ class StudentAPI(IStudentAPI, IGameTimer):

# 等待下一帧

def Wait(self) -> Future[bool]:
def Wait(self) -> bool:
if self.__logic.GetCounter() == -1:
return self.__pool.submit(lambda: False)
return False
else:
return self.__pool.submit(self.__logic.WaitThread)
return self.__logic.WaitThread()

# 获取各类游戏中的消息

@@ -252,11 +252,11 @@ class TrickerAPI(ITrickerAPI, IGameTimer):

# 等待下一帧

def Wait(self) -> Future[bool]:
def Wait(self) -> bool:
if self.__logic.GetCounter() == -1:
return self.__pool.submit(lambda: False)
return False
else:
return self.__pool.submit(self.__logic.WaitThread)
return self.__logic.WaitThread()

# 获取各类游戏中的消息



+ 6
- 6
CAPI/python/PyAPI/DebugAPI.py View File

@@ -249,13 +249,13 @@ class StudentDebugAPI(IStudentAPI, IGameTimer):

# 等待下一帧

def Wait(self) -> Future[bool]:
def Wait(self) -> bool:
self.__logger.info(
f"Wait: called at {self.__GetTime()}ms")
if self.__logic.GetCounter() == -1:
return self.__pool.submit(lambda: False)
return False
else:
return self.__pool.submit(self.__logic.WaitThread)
return self.__logic.WaitThread()

# 获取各类游戏中的消息

@@ -701,13 +701,13 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer):

# 等待下一帧

def Wait(self) -> Future[bool]:
def Wait(self) -> bool:
self.__logger.info(
f"Wait: called at {self.__GetTime()}ms")
if self.__logic.GetCounter() == -1:
return self.__pool.submit(lambda: False)
return False
else:
return self.__pool.submit(self.__logic.WaitThread)
return self.__logic.WaitThread()

# 获取各类游戏中的消息



+ 1
- 1
CAPI/python/PyAPI/Interface.py View File

@@ -245,7 +245,7 @@ class IAPI(metaclass=ABCMeta):
# 等待下一帧

@abstractmethod
def Wait(self) -> Future[bool]:
def Wait(self) -> bool:
pass

# 获取各类游戏中的消息


+ 0
- 2
installer/Installer/Installer.csproj View File

@@ -6,11 +6,9 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<AppHostDotNetRoot>dotNetRuntime</AppHostDotNetRoot>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dotnetCampus.AppHost" Version="1.0.0-alpha10" />
<PackageReference Include="ICSharpCode.SharpZipLib.dll" Version="0.85.4.369" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />


+ 33
- 15
installer/Installer/Model.cs View File

@@ -691,12 +691,14 @@ namespace Downloader
catch (CosClientException clientEx)
{
// 请求失败
MessageBox.Show("网络错误");
Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine);
return;
}
catch (CosServerException serverEx)
{
// 请求失败
MessageBox.Show("网络错误");
Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine);
return;
}
@@ -1195,9 +1197,11 @@ namespace Downloader

public static int CheckSelfVersion()
{
string keyHead = "Installer/";
Tencent_cos_download downloader = new Tencent_cos_download();
string hashName = "installerHash.json";
string dir = Directory.GetCurrentDirectory();
int result = 0;
try
{
if (File.Exists(System.IO.Path.Combine(dir, hashName)))
@@ -1213,28 +1217,42 @@ namespace Downloader
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
string md5 = "";
List<string> awaitUpdate = new List<string>();
if (jsonDict != null)
{
if (jsonDict.ContainsKey("InstallerUpdater.exe"))
{
string updaterHash = GetFileMd5Hash(System.IO.Path.Combine(dir, "InstallerUpdater.exe"));
if (updaterHash != null && !jsonDict["InstallerUpdater.exe"].Equals(updaterHash))
downloader.download(System.IO.Path.Combine(dir, "InstallerUpdater.exe"), "InstallerUpdater.exe");
}
else
return -1;
if (jsonDict.ContainsKey("Installer.exe"))
foreach (KeyValuePair<string, string> pair in jsonDict)
{
string selfHash = GetFileMd5Hash(System.IO.Path.Combine(dir, "Installer.exe"));
if (selfHash != null && !jsonDict["Installer.exe"].Equals(selfHash))
return 1;
md5 = GetFileMd5Hash(System.IO.Path.Combine(dir, pair.Key));
if (md5.Length == 0) // 文档不存在
{
downloader.download(System.IO.Path.Combine(dir, pair.Key), keyHead + pair.Key);
}
else if (md5.Equals("conflict"))
{
MessageBox.Show($"检查{pair.Key}更新时遇到问题,请反馈", "读取出错", MessageBoxButton.OK, MessageBoxImage.Error);
}
else if (md5 != pair.Value) // MD5不匹配
{
if (pair.Key.Substring(0, 12).Equals("InstallerUpd"))
{
File.Delete(System.IO.Path.Combine(dir, pair.Key));
downloader.download(System.IO.Path.Combine(dir, pair.Key), keyHead + pair.Key);
}
else
{
result = 1;
awaitUpdate.Append(pair.Key);
}
}
}
else
return -1;
}
else
return -1;
return 0;
string Contentjson = JsonConvert.SerializeObject(awaitUpdate);
Contentjson = Contentjson.Replace("\r", String.Empty).Replace("\n", String.Empty).Replace(@"\\", "/");
File.WriteAllText(@System.IO.Path.Combine(dir, "updateList.json"), Contentjson);
return result;
}
}
}


+ 8
- 1
installer/Installer/ViewModel.cs View File

@@ -33,7 +33,7 @@ namespace starter.viewmodel.settings
public SettingsViewModel()
{

//Program.Tencent_cos_download.UpdateHash();
Program.Tencent_cos_download.UpdateHash();

Status = SettingsModel.Status.working;

@@ -152,6 +152,13 @@ namespace starter.viewmodel.settings
if (asyncUpdater.CancellationPending)
{
e.Cancel = true;
MessageBox.Show("下载取消");
if (e.Argument.ToString().Equals("Manual"))
{
Status = SettingsModel.Status.menu;
}
else
Status = SettingsModel.Status.login;
return;
}
else


+ 1
- 3
installer/InstallerUpdater/InstallerUpdater.csproj View File

@@ -5,14 +5,12 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AppHostDotNetRoot>dotNetRuntime</AppHostDotNetRoot>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dotnetCampus.AppHost" Version="1.0.0-alpha10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.34">
<TreatAsUsed>true</TreatAsUsed>
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
</ItemGroup>



+ 1
- 0
installer/InstallerUpdater/MainWindow.xaml.cs View File

@@ -28,6 +28,7 @@ namespace InstallerUpdater
public MainWindow()
{
InitializeComponent();
MessageBox.Show("这是旧版");
asyncDownloader.DoWork += AsyncDownloader_DoWork;
asyncDownloader.RunWorkerCompleted += AsyncDownloader_RunWorkerCompleted;
if (asyncDownloader.IsBusy)


+ 11
- 3
installer/InstallerUpdater/Program.cs View File

@@ -19,14 +19,22 @@ namespace Program
public static string Dir = Directory.GetCurrentDirectory();
public static string InstallerName = "Installer.exe";
public static string jsonKey = "installerHash.json";
public static string KeyHead = "Installer/";

public static bool UpdateInstaller()
{
string json;
try
{
download(Path.Combine(Dir, "newInstaller.exe"), InstallerName);
File.Delete(Path.Combine(Dir, InstallerName));
File.Move(Path.Combine(Dir, "newInstaller.exe"), Path.Combine(Dir, InstallerName));
using (StreamReader r = new StreamReader(System.IO.Path.Combine(Dir, "updateList.json")))
json = r.ReadToEnd();
json = json.Replace("\r", string.Empty).Replace("\n", string.Empty);
List<string> jsonList = JsonConvert.DeserializeObject<List<string>>(json);
foreach (string todo in jsonList)
{
File.Delete(Path.Combine(Dir, todo));
download(Path.Combine(Dir, todo), KeyHead + todo);
}
}
catch
{


Loading…
Cancel
Save