mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 10:10:45 +08:00
merge "Updater interface modified"
This commit is contained in:
@@ -22,7 +22,8 @@ namespace asst {
|
||||
|
||||
static Updater& instance();
|
||||
|
||||
std::optional<VersionInfo> has_new_version();
|
||||
bool has_new_version();
|
||||
const VersionInfo & get_version_info() const noexcept;
|
||||
|
||||
private:
|
||||
Updater() = default;
|
||||
|
||||
@@ -74,11 +74,11 @@ bool AsstGetParam(asst::Assistance* p_asst, const char* type, const char* param,
|
||||
|
||||
bool CheckVersionUpdate(char* tag_buffer, int tag_bufsize, char* html_url_buffer, int html_bufsize, char* body_buffer, int body_bufsize)
|
||||
{
|
||||
auto ret = asst::Updater::instance().has_new_version();
|
||||
bool ret = asst::Updater::instance().has_new_version();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
auto info = std::move(ret).value();
|
||||
auto && info = asst::Updater::instance().get_version_info();
|
||||
strcpy_s(tag_buffer, tag_bufsize, info.tag_name.c_str());
|
||||
strcpy_s(html_url_buffer, html_bufsize, info.html_url.c_str());
|
||||
strcpy_s(body_buffer, body_bufsize, info.body.c_str());
|
||||
|
||||
@@ -18,17 +18,17 @@ Updater& Updater::instance()
|
||||
return unique_instance;
|
||||
}
|
||||
|
||||
std::optional<VersionInfo> Updater::has_new_version()
|
||||
bool Updater::has_new_version()
|
||||
{
|
||||
auto req_ret = request_github_api();
|
||||
if (!req_ret) {
|
||||
DebugTraceInfo("Requeset Error");
|
||||
return std::nullopt;
|
||||
return false;
|
||||
}
|
||||
auto parse_ret = json::parser::parse(req_ret.value());
|
||||
if (!parse_ret) {
|
||||
DebugTraceInfo("Parse Error");
|
||||
return std::nullopt;
|
||||
return false;
|
||||
}
|
||||
|
||||
json::value root = std::move(parse_ret).value();
|
||||
@@ -46,19 +46,26 @@ std::optional<VersionInfo> Updater::has_new_version()
|
||||
}
|
||||
catch (json::exception& exp) {
|
||||
DebugTraceError("Json Error", exp.what());
|
||||
return std::nullopt;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lastest_version.tag_name > Version) {
|
||||
m_has_new_version = true;
|
||||
return m_lastest_version;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
m_has_new_version = false;
|
||||
return std::nullopt;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const VersionInfo & Updater::get_version_info() const noexcept
|
||||
{
|
||||
if (!m_has_new_version) {
|
||||
return VersionInfo();
|
||||
}
|
||||
return m_lastest_version;
|
||||
}
|
||||
|
||||
std::optional<std::string> Updater::request_github_api()
|
||||
{
|
||||
HINTERNET h_session = ::InternetOpenA("GithubRelease", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:MeoAsstGui"
|
||||
mc:Ignorable="d"
|
||||
Title="MeoAssistance-明日方舟辅助" Height="500" Width="400">
|
||||
Title="Meo明日方舟辅助" Height="500" Width="400" Loaded="OnLoaded">
|
||||
<Grid>
|
||||
<CheckBox x:Name="checkBox_useMedicine" Content="吃理智药" HorizontalAlignment="Left" Margin="50,100,0,0" VerticalAlignment="Top" Checked="checkBox_useMedicine_Checked" Unchecked="checkBox_useMedicine_Checked" IsChecked="True"/>
|
||||
<CheckBox x:Name="checkBox_useStone" Content="吃石头" HorizontalAlignment="Left" Margin="50,150,0,0" VerticalAlignment="Top" Checked="checkBox_useStone_Checked" Unchecked="checkBox_useStone_Checked"/>
|
||||
|
||||
@@ -36,25 +36,28 @@ namespace MeoAsstGui
|
||||
|
||||
|
||||
private IntPtr p_asst;
|
||||
UpdateDialog updateDialog;
|
||||
private DispatcherTimer update_times = new DispatcherTimer();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
UpdateDialog dialog = new UpdateDialog();
|
||||
dialog.CheckUpdateAndShowDialog();
|
||||
dialog.Close();
|
||||
|
||||
p_asst = CreateAsst();
|
||||
update_times.Tick += new EventHandler(updateExecTimes);
|
||||
update_times.Interval = TimeSpan.FromSeconds(1);
|
||||
}
|
||||
~MainWindow()
|
||||
{
|
||||
DestoryAsst(p_asst);
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
updateDialog = new UpdateDialog();
|
||||
updateDialog.CheckUpdateAndShowDialog();
|
||||
updateDialog.Close();
|
||||
|
||||
p_asst = CreateAsst();
|
||||
update_times.Tick += new EventHandler(updateExecTimes);
|
||||
update_times.Interval = TimeSpan.FromSeconds(1);
|
||||
}
|
||||
private void button_Click_startSanity(object sender, RoutedEventArgs e)
|
||||
{
|
||||
bool catched = AsstCatchSimulator(p_asst);
|
||||
|
||||
@@ -5,7 +5,12 @@ int main(int argc, char** argv)
|
||||
{
|
||||
using namespace asst;
|
||||
|
||||
auto up = Updater::instance().has_new_version();
|
||||
bool up = Updater::instance().has_new_version();
|
||||
if (up) {
|
||||
auto && info = Updater::instance().get_version_info();
|
||||
std::cout << "ÓÐа汾£º" << info.tag_name << std::endl;
|
||||
std::cout << "µØÖ·£º" << info.html_url << std::endl;
|
||||
}
|
||||
|
||||
Assistance asst;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user