updater.cpp

main 92 lines · 2.2 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19
20#ifdef _USE_UPDATER_
21
22 #include <wx/url.h>
23
24 #include "json.h"
25
26 #include "updater.h"
27
28const wxEventType EVT_UPDATE_CHECK_FINISHED = wxNewEventType();
29
30UpdateChecker::UpdateChecker() {
31 ////
32}
33
34UpdateChecker::~UpdateChecker() {
35 ////
36}
37
38void UpdateChecker::connect(wxEvtHandler* receiver) {
39 wxString address = "http://www.remeresmapeditor.com/update.php";
40 address << "?os="
41 <<
42 #ifdef __WINDOWS__
43 "windows";
44 #elif __LINUX__
45 "linux";
46 #else
47 "unknown";
48 #endif
49 address << "&verid=" << __RME_VERSION_ID__;
50 #ifdef __EXPERIMENTAL__
51 address << "&beta";
52 #endif
53 wxURL* url = newd wxURL(address);
54 UpdateConnectionThread* connection = newd UpdateConnectionThread(receiver, url);
55 connection->Execute();
56}
57
58UpdateConnectionThread::UpdateConnectionThread(wxEvtHandler* receiver, wxURL* url) :
59 receiver(receiver),
60 url(url) {
61 ////
62}
63
64UpdateConnectionThread::~UpdateConnectionThread() {
65 ////
66}
67
68wxThread::ExitCode UpdateConnectionThread::Entry() {
69 wxInputStream* input = url->GetInputStream();
70 if (!input) {
71 delete input;
72 delete url;
73 return 0;
74 }
75
76 std::string data;
77 while (!input->Eof()) {
78 data += input->GetC();
79 }
80
81 delete input;
82 delete url;
83 wxCommandEvent event(EVT_UPDATE_CHECK_FINISHED);
84 event.SetClientData(newd std::string(data));
85 if (receiver) {
86 receiver->AddPendingEvent(event);
87 }
88 return 0;
89}
90
91#endif
92
Top