-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathactivation.cpp
107 lines (95 loc) · 3.76 KB
/
activation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "interface_derived.hpp"
#include "activation.hpp"
#include "fmt/format.h"
#include <wx/process.h>
#include <wx/filedlg.h>
#include <fstream>
#include "output_dialog.hpp"
using namespace std;
wxBEGIN_EVENT_TABLE(PersonalActivationDlg, wxDialog)
EVT_BUTTON(PAD_CREATE, PersonalActivationDlg::OnCreateHit)
EVT_BUTTON(PAD_ACTIVATE, PersonalActivationDlg::OnActivateHit)
wxEND_EVENT_TABLE()
wxBEGIN_EVENT_TABLE(PlusProActivationDlg, wxDialog)
EVT_BUTTON(PPA_ACTIVATE, PlusProActivationDlg::OnActivateHit)
wxEND_EVENT_TABLE()
void MainFrameDerived::OnActivatePersonal(wxCommandEvent& event) {
auto selected = installsList->GetSelection();
if (selected != -1) {
const auto& editor = editors[selected];
auto dlg = new PersonalActivationDlg(this, editor);
dlg->ShowModal();
}
}
void MainFrameDerived::OnActivateProPlus(wxCommandEvent& event) {
auto selected = installsList->GetSelection();
if (selected != -1) {
const auto& editor = editors[selected];
auto dlg = new PlusProActivationDlg(this, editor);
dlg->ShowModal();
}
}
void PersonalActivationDlg::OnCreateHit(wxCommandEvent& evt)
{
wxFileDialog saveFileDialog(this, _("Save Activation file"), "", "activation.alf", "ALF files (*.alf)|*.alf", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (saveFileDialog.ShowModal() == wxID_CANCEL) {}
else {
// pass the chosen location
auto exe = the_editor.executablePath().string();
auto cmd = fmt::format("{} -batchmode -createManualActivationFile -logfile",exe);
auto cwd = wxGetCwd();
auto root = std::filesystem::path(saveFileDialog.GetPath().ToStdString()).parent_path();
wxSetWorkingDirectory(root.string());
wxProcess proc(wxPROCESS_DEFAULT);
wxExecute(cmd, wxEXEC_SYNC);
reveal_in_explorer(std::filesystem::path(wxGetCwd().ToStdString()));
wxSetWorkingDirectory(cwd);
}
}
void DisplayLicenseOutput(){
std::filesystem::path logfile
#ifdef __APPLE__
= std::filesystem::path(wxGetHomeDir()) / "Library/Logs/Unity/Editor.log";
#elif defined _WIN32
= std::filesystem::path(wxGetHomeDir().ToStdString()) / "AppData"/"Local"/"Unity"/"Editor"/"Editor.log";
#else
= std::filesystem::path(wxGetHomeDir()) / ".config/unity3d/Editor.log";
#endif
ifstream in(logfile);
std::string output;
std::string line;
while (getline(in, line)){
auto cpy = line;
transform(cpy.begin(), cpy.end(), cpy.begin(), ::tolower);
// filter for license-related lines
if (cpy.find("licens") != decltype(line)::npos){
output += line;
}
}
auto dialog = new OutputDialog(nullptr, output, "Activation status");
dialog->ShowModal();
}
void PersonalActivationDlg::OnActivateHit(wxCommandEvent&)
{
wxFileDialog openFileDialog(this, _("Open License file"), "", "", "ULF files (*.ulf)|*.ulf", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL) {}
else {
auto exe = the_editor.executablePath().string();
auto cmd = fmt::format("{} -batchmode -manualLicenseFile \"{}\" -logfile",exe,openFileDialog.GetPath().ToStdString());
activateBtn->SetLabelText("Activating...");
wxExecute(cmd, wxEXEC_SYNC);
DisplayLicenseOutput();
this->Close();
}
}
void PlusProActivationDlg::OnActivateHit(wxCommandEvent&)
{
const std::string& username = plusProActivUsernameCtrl->GetValue();
const std::string& password = plusProActivPasswordCtrl->GetValue();
const std::string& serial = plusProActivationSerialCtrl->GetValue();
auto cmd = fmt::format("{} -batchmode -username {} -password {} -serial {} -quit",the_editor.executablePath().string(),username,password,serial);
activateBtn->SetLabelText("Activating...");
wxExecute(cmd, wxEXEC_SYNC);
DisplayLicenseOutput();
this->Close();
}