mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Modified update checker to get it to compile
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@605 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+74
-61
@@ -179,11 +179,11 @@ void show_update_dialog(Window* parent) {
|
||||
shown_dialog = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : UpdateWindow
|
||||
// ----------------------------------------------------------------------------- : PackageUpdateList
|
||||
|
||||
class PackageUpdateList: public wxVListBox {
|
||||
class PackageUpdateList : public wxVListBox {
|
||||
public:
|
||||
PackageUpdateList(UpdateWindow * parent)
|
||||
PackageUpdateList(UpdatesWindow* parent)
|
||||
: wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL)
|
||||
, parent(parent)
|
||||
{
|
||||
@@ -192,47 +192,49 @@ class PackageUpdateList: public wxVListBox {
|
||||
}
|
||||
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
|
||||
}
|
||||
|
||||
|
||||
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
|
||||
static wxBrush greyBrush(Color(224,224,224));
|
||||
if (checking_updates) {
|
||||
String text = _ERROR_("checking updates");
|
||||
wxSize text_size = dc.GetTextExtent(text);
|
||||
|
||||
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(greyBrush);
|
||||
dc.DrawRectangle(rect);
|
||||
|
||||
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2);
|
||||
|
||||
int w, h;
|
||||
dc.GetTextExtent(text, &w, &h);
|
||||
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
|
||||
} else if (!update_version_data || update_version_data->packages.empty()) {
|
||||
String text = _ERROR_("no packages");
|
||||
wxSize text_size = dc.GetTextExtent(text);
|
||||
|
||||
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(greyBrush);
|
||||
dc.DrawRectangle(rect);
|
||||
|
||||
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2);
|
||||
|
||||
int w, h;
|
||||
dc.GetTextExtent(text, &w, &h);
|
||||
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
|
||||
} else {
|
||||
static wxBrush darkBrush(Color(192,224,255));
|
||||
static wxBrush selectBrush(Color(96,96,192));
|
||||
|
||||
|
||||
PackageVersionDataP pack = update_version_data->packages[n];
|
||||
UpdateWindow::PackageStatus status = parent->package_data[pack].first;
|
||||
UpdateWindow::PackageAction action = parent->package_data[pack].second;
|
||||
|
||||
UpdatesWindow::PackageStatus status = parent->package_data[pack].first;
|
||||
UpdatesWindow::PackageAction action = parent->package_data[pack].second;
|
||||
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush));
|
||||
|
||||
|
||||
dc.DrawRectangle(rect);
|
||||
|
||||
|
||||
// These two arrays correspond to PackageStatus and PackageAction, respectively
|
||||
static Color status_colors [] = {
|
||||
Color(32,160,32)
|
||||
,Color(32,32,255)
|
||||
,Color(192,32,32)
|
||||
};
|
||||
|
||||
|
||||
static Color action_colors [] = {
|
||||
Color(32,160,32)
|
||||
,Color(192,32,32)
|
||||
@@ -240,14 +242,14 @@ class PackageUpdateList: public wxVListBox {
|
||||
,Color(32,32,255)
|
||||
,Color(32,32,32)
|
||||
};
|
||||
|
||||
|
||||
// Ditto here (these are the locale names)
|
||||
static String status_texts [] = {
|
||||
_TYPE_("installed")
|
||||
,_TYPE_("uninstalled")
|
||||
,_TYPE_("upgradeable")
|
||||
};
|
||||
|
||||
|
||||
static String action_texts [] = {
|
||||
_TYPE_("install")
|
||||
,_TYPE_("uninstall")
|
||||
@@ -255,98 +257,109 @@ class PackageUpdateList: public wxVListBox {
|
||||
,_TYPE_("do nothing")
|
||||
,_TYPE_("new mse")
|
||||
};
|
||||
|
||||
static Color textBack(0,0,0,wxALPHA_TRANSPARENT);
|
||||
|
||||
// this doesn't work for me, is it really necessary?
|
||||
//static Color textBack(0,0,0,wxALPHA_TRANSPARENT);
|
||||
static Color packageFront(64,64,64);
|
||||
|
||||
|
||||
#define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color)
|
||||
|
||||
|
||||
dc.SetTextForeground(SELECT_WHITE(packageFront));
|
||||
dc.SetTextBackground(textBack);
|
||||
//dc.SetTextBackground(textBack);
|
||||
dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop());
|
||||
|
||||
|
||||
dc.SetTextForeground(SELECT_WHITE(status_colors[status]));
|
||||
dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop());
|
||||
|
||||
|
||||
dc.SetTextForeground(SELECT_WHITE(action_colors[action]));
|
||||
dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop());
|
||||
|
||||
|
||||
#undef SELECT_INVERT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual wxCoord OnMeasureItem(size_t) const {
|
||||
return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210;
|
||||
}
|
||||
|
||||
|
||||
void onUpdateCheckingFinished(wxEvent& event) {
|
||||
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
|
||||
}
|
||||
|
||||
|
||||
virtual wxCoord EstimateTotalHeight() const {
|
||||
return (update_version_data && !update_version_data->packages.empty()) ? 15 * update_version_data->packages.size() : 210;
|
||||
return (update_version_data && !update_version_data->packages.empty())
|
||||
? 15 * (int)update_version_data->packages.size()
|
||||
: 210;
|
||||
}
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
UpdateWindow * parent;
|
||||
UpdatesWindow* parent;
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox)
|
||||
EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, -1, PackageUpdateList::onUpdateCheckingFinished)
|
||||
EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, wxID_ANY, PackageUpdateList::onUpdateCheckingFinished)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
UpdateWindow::UpdateWindow()
|
||||
// ----------------------------------------------------------------------------- : UpdateWindow
|
||||
|
||||
UpdatesWindow::UpdatesWindow()
|
||||
: Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,375), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN)
|
||||
{
|
||||
SetIcon(wxIcon());
|
||||
wxBoxSizer *v = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
|
||||
package_list = new PackageUpdateList(this);
|
||||
description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
|
||||
|
||||
wxCommandEvent ev;
|
||||
SetDefaultPackageStatus(ev);
|
||||
|
||||
package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
|
||||
setDefaultPackageStatus();
|
||||
|
||||
// TODO: No absolute positioning please!
|
||||
package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
|
||||
package_title->Move(1,0);
|
||||
status_title->Move(240,0);
|
||||
new_title->Move(360,0);
|
||||
|
||||
|
||||
v->AddSpacer(15);
|
||||
v->Add(package_list);
|
||||
v->Add(description_window);
|
||||
|
||||
|
||||
SetSizer(v);
|
||||
}
|
||||
|
||||
void UpdateWindow::SetDefaultPackageStatus(wxCommandEvent&)
|
||||
{
|
||||
if (!update_version_data)
|
||||
return;
|
||||
void UpdatesWindow::onUpdateCheckFinished(wxCommandEvent&) {
|
||||
setDefaultPackageStatus();
|
||||
}
|
||||
|
||||
void UpdatesWindow::setDefaultPackageStatus() {
|
||||
if (!update_version_data) return;
|
||||
FOR_EACH(p, update_version_data->packages) {
|
||||
PackagedP pack;
|
||||
try { pack = packages.openAny(p->name); }
|
||||
catch (Error& e) { } // We couldn't open a package... wonder why?
|
||||
|
||||
try { pack = packages.openAny(p->name, true); }
|
||||
catch (const Error&) { } // We couldn't open a package... wonder why?
|
||||
|
||||
if (!pack) {
|
||||
if (p->app_version > file_version)
|
||||
// not installed
|
||||
if (p->app_version > file_version) {
|
||||
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NEW_MSE);
|
||||
else
|
||||
} else {
|
||||
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING);
|
||||
}
|
||||
} else if (pack->version < p->version) {
|
||||
if (p->app_version > file_version)
|
||||
// newer version
|
||||
if (p->app_version > file_version) {
|
||||
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_NEW_MSE);
|
||||
else
|
||||
} else {
|
||||
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE);
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(UpdateWindow, Frame)
|
||||
EVT_COMMAND(-1, UPDATE_CHECK_FINISHED_EVT, UpdateWindow::SetDefaultPackageStatus)
|
||||
BEGIN_EVENT_TABLE(UpdatesWindow, Frame)
|
||||
EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, UpdatesWindow::onUpdateCheckFinished)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
Reference in New Issue
Block a user