Commit a70fe2a7 authored by Melroy van den Berg's avatar Melroy van den Berg
Browse files

Working winecfg & winetricks

parent da849ba3
......@@ -60,11 +60,14 @@ public:
void SetActiveBottle(BottleItem* bottle);
const Glib::ustring& GetErrorMessage();
// Signal handlers
void RunProgram(string filename, bool is_msi_file);
void OpenDriveC();
void Reboot();
void Update();
void KillProcesses();
void OpenWinecfg();
void OpenWinetricks();
private:
// Synchronizes access to data members
mutable std::mutex m_Mutex;
......
......@@ -44,13 +44,9 @@ protected:
// Child widgets
Gtk::Grid settings_grid;
Gtk::Label first_row_label;
Gtk::Label second_row_label;
Gtk::Toolbar first_toolbar;
Gtk::Toolbar second_toolbar;
Gtk::Label label;
// Buttons first row
Gtk::ToolButton edit_button; /*!< edit button */
Gtk::ToolButton save_button; /*!< save button */
Gtk::ToolButton delete_button; /*!< delete button */
// Buttons second row
......
......@@ -46,7 +46,8 @@ public:
static Helper& getInstance();
static std::map<string, unsigned long> GetBottlesPaths(const string& dir_path);
static void RunProgram(string prefix_path, string program, bool is_msi_file);
static void RunProgramUnderWine(string prefix_path, string program, bool enable_tracing, bool is_msi_file);
static void RunProgramWithPrefix(string prefix_path, string program, bool enable_tracing, bool give_error);
static string GetWineVersion();
static void CreateWineBottle(const string prefix_path, BottleTypes::Bit bit);
static void RemoveWineBottle(const string prefix_path);
......@@ -77,7 +78,7 @@ private:
Helper& operator=(const Helper&)= delete;
static string Exec(const char* cmd);
static void WineExec(const char* cmd, bool enableTracing = false);
static void ExecTracing(const char* cmd, bool enableTracing);
static int CloseFile(std::FILE* file);
static string GetRegValue(const string& filename, const string& keyName, const string& valueName);
static string GetRegMetaData(const string& filename, const string& metaValueName);
......
......@@ -44,6 +44,8 @@ BottleManager::BottleManager(MainWindow& mainWindow):
// TODO: Make it configurable via settings
std::vector<std::string> dirs{Glib::get_home_dir(), ".winegui", "prefixes"};
BOTTLE_LOCATION = Glib::build_path(G_DIR_SEPARATOR_S, dirs);
// TODO: Enable/disable tracing for the RunProgram commands (and make it configurable)
}
/**
......@@ -298,7 +300,7 @@ void BottleManager::RunProgram(string filename, bool is_msi_file = false)
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
std::thread t(&Helper::RunProgram, wine_prefix, filename, is_msi_file);
std::thread t(&Helper::RunProgramUnderWine, wine_prefix, filename, false, is_msi_file);
t.detach();
}
}
......@@ -324,7 +326,7 @@ void BottleManager::Reboot()
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
std::thread t(&Helper::RunProgram, wine_prefix, "wineboot -r", false);
std::thread t(&Helper::RunProgramUnderWine, wine_prefix, "wineboot -r", false, false);
t.detach();
}
}
......@@ -336,7 +338,7 @@ void BottleManager::Update()
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
std::thread t(&Helper::RunProgram, wine_prefix, "wineboot -u", false);
std::thread t(&Helper::RunProgramUnderWine, wine_prefix, "wineboot -u", false, false);
t.detach();
}
}
......@@ -348,7 +350,32 @@ void BottleManager::KillProcesses()
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
std::thread t(&Helper::RunProgram, wine_prefix, "wineboot -k", false);
std::thread t(&Helper::RunProgramUnderWine, wine_prefix, "wineboot -k", false, false);
t.detach();
}
}
/**
* \brief Open Winecfg tool (expected to be installed)
*/
void BottleManager::OpenWinecfg()
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
std::thread t(&Helper::RunProgramWithPrefix, wine_prefix, "winecfg", false, true);
t.detach();
}
}
/**
* \brief Open Winetricks tool in GUI mode
*/
void BottleManager::OpenWinetricks()
{
if (isBottleNotNull()) {
Glib::ustring wine_prefix = activeBottle->wine_location();
string program = Helper::GetWinetricksLocation() + " --gui";
std::thread t(&Helper::RunProgramWithPrefix, wine_prefix, program, false, false);
t.detach();
}
}
......
......@@ -27,7 +27,7 @@
*/
EditWindow::EditWindow(Gtk::Window& parent)
:
edit_button("Edit Configuration"),
save_button("Save"),
delete_button("Delete Machine"),
wine_config_button("WineCfg"),
activeBottle(nullptr)
......@@ -36,45 +36,6 @@ EditWindow::EditWindow(Gtk::Window& parent)
set_default_size(750, 540);
set_modal(true);
add(settings_grid);
settings_grid.set_margin_top(5);
settings_grid.set_margin_end(5);
settings_grid.set_margin_bottom(8);
settings_grid.set_margin_start(8);
settings_grid.set_column_spacing(8);
settings_grid.set_row_spacing(12);
first_row_label.set_text("WineGUI Settings");
first_row_label.set_xalign(0);
second_row_label.set_text("Other Tools Settings");
second_row_label.set_xalign(0);
first_toolbar.set_toolbar_style(Gtk::ToolbarStyle::TOOLBAR_BOTH);
first_toolbar.set_halign(Gtk::ALIGN_CENTER);
first_toolbar.set_hexpand(true);
second_toolbar.set_toolbar_style(Gtk::ToolbarStyle::TOOLBAR_BOTH);
second_toolbar.set_halign(Gtk::ALIGN_CENTER);
second_toolbar.set_hexpand(true);
settings_grid.attach(first_row_label, 0, 0, 1, 1);
settings_grid.attach(first_toolbar, 0, 1, 1, 1);
settings_grid.attach(second_row_label, 0, 2, 1, 1);
settings_grid.attach(second_toolbar, 0, 3, 1, 1);
// First row with buttons
Gtk::Image* edit_image = Gtk::manage(new Gtk::Image());
edit_image->set_from_icon_name("document-edit", Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
edit_button.set_icon_widget(*edit_image);
first_toolbar.insert(edit_button, 0);
Gtk::Image* delete_image = Gtk::manage(new Gtk::Image());
delete_image->set_from_icon_name("edit-delete", Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
delete_button.set_icon_widget(*delete_image);
delete_button.set_border_width(2);
first_toolbar.insert(delete_button, 1);
// Second row with buttons
second_toolbar.insert(wine_config_button, 0);
show_all_children();
}
......
......@@ -129,19 +129,45 @@ std::map<std::string, unsigned long> Helper::GetBottlesPaths(const string& dir_p
}
/**
* \brief Run program under Wine (run in thread, and dettach it)
* \param[in] prefix_path - The path to create a Wine bottle from
* \brief Run a Windows program under Wine (run in thread, and dettach it)
* \param[in] prefix_path - The path to bottle wine
* \param[in] program - Program/executable that will be executed
* \param[in] is_msi_file - Is the program a MSI installer, let's instal it (default false)
* \param[in] enable_tracing - Enable debugging tracing to file
* \param[in] is_msi_file - Is the program a MSI installer, let's instal it
*/
void Helper::RunProgram(string prefix_path, string program, bool is_msi_file)
void Helper::RunProgramUnderWine(string prefix_path, string program, bool enable_tracing, bool is_msi_file)
{
string msi = "";
if (is_msi_file) {
msi = " msiexec /i";
}
// Execute the command and show the user a message when exit code is non-zero
WineExec(("WINEPREFIX=\"" + prefix_path + "\"" + msi + " " + WINE_EXECUTABLE + " " + program).c_str());
ExecTracing(("WINEPREFIX=\"" + prefix_path + "\"" + msi + " " + WINE_EXECUTABLE + " " + program).c_str(), enable_tracing);
}
/**
* \brief Run any program with only setting the WINEPREFIX env variable.
* \param[in] prefix_path - The path to wine bottle
* \param[in] program - Program that gets executed (ideally full path)
* \param[in] enable_tracing - Enable debugging tracing to file (give_error should be true as well!)
* \param[in] give_error - Inform user when application exit with non-zero exit code
*/
void Helper::RunProgramWithPrefix(string prefix_path, string program, bool enable_tracing, bool give_error)
{
bool execTracing = false;
if (enable_tracing) {
execTracing = true;
}
if(!give_error) {
execTracing = false;
}
if (execTracing) {
// Execute the command and show the user a message when exit code is non-zero
ExecTracing(("WINEPREFIX=\"" + prefix_path + "\" " + program).c_str(), enable_tracing);
} else {
// No tracing and no error message when exit code is non-zero
Exec(("WINEPREFIX=\"" + prefix_path + "\" " + program).c_str());
}
}
/**
......@@ -594,17 +620,6 @@ string Helper::GetWinetricksVersion()
return version;
}
/**
* \brief Show the Winetricks userinterface
*/
void Helper::ShowWinetricksGUI(const string prefix_path)
{
if (FileExists(WINETRICKS_EXECUTABLE))
{
Exec(("WINEPREFIX=\"" + prefix_path + "\" " + WINETRICKS_EXECUTABLE + " --gui").c_str());
}
}
/**
* \brief Set Windows OS version by using Winetricks
*/
......@@ -718,7 +733,14 @@ void Helper::SetAudioDriver(const string prefix_path, BottleTypes::AudioDriver a
*/
string Helper::GetWinetricksLocation()
{
return WINETRICKS_EXECUTABLE;
string path = "";
if (FileExists(WINETRICKS_EXECUTABLE))
{
path = WINETRICKS_EXECUTABLE;
} else {
g_warning("Could not find winetricks executable!");
}
return path;
}
/****************************************************************************
......@@ -747,12 +769,13 @@ string Helper::Exec(const char* cmd) {
}
/**
* \brief Execute command on terminal. Return output.
* \brief Execute command on terminal, give user an error went something went wrong.
* Also write output to log (if debugging is enabled).
* \param[in] cmd The command to be executed
* \param[in] enableTracing Enable debugging tracing to log file
* \param[in] enableTracing Enable debugging tracing to log file (default false)
* \return Terminal stdout
*/
void Helper::WineExec(const char* cmd, bool enableTracing) {
void Helper::ExecTracing(const char* cmd, bool enableTracing) {
// Max 128 characters
std::array<char, 128> buffer;
string result = "";
......
......@@ -93,9 +93,6 @@ void SignalDispatcher::DispatchSignals()
menu.menu_settings_machine.connect(sigc::mem_fun(settingsWindow, &SettingsWindow::Show));
menu.menu_remove_machine.connect(sigc::mem_fun(manager, &BottleManager::DeleteBottle));
// signal_show_edit_window.connect(sigc::mem_fun(editWindow, &EditWindow::Show));
// signal_show_settings_window.connect(sigc::mem_fun(settingsWindow, &SettingsWindow::Show));
// Distribute the active bottle signal
mainWindow->activeBottle.connect(sigc::mem_fun(manager, &BottleManager::SetActiveBottle));
mainWindow->activeBottle.connect(sigc::mem_fun(editWindow, &EditWindow::SetActiveBottle));
......@@ -129,8 +126,9 @@ void SignalDispatcher::DispatchSignals()
helper.failureOnExec.connect(sigc::mem_fun(*mainWindow, &MainWindow::on_exec_failure));
// Settings buttons
// settingsWindow.directx.connect()
// settingsWindow.winetricks.connect()
//settingsWindow.directx.connect()
settingsWindow.winetricks.connect(sigc::mem_fun(manager, &BottleManager::OpenWinetricks));
settingsWindow.winecfg.connect(sigc::mem_fun(manager, &BottleManager::OpenWinecfg));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment