diff --git a/lib/asterisk/states/game_form.rb b/lib/asterisk/states/game_form.rb index 0246c73..122f51a 100644 --- a/lib/asterisk/states/game_form.rb +++ b/lib/asterisk/states/game_form.rb @@ -31,7 +31,7 @@ class W3DHub flow(width: 1.0, fill: true) do @game_path = edit_line "#{@game&.path}", fill: true, height: 1.0 - button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do + button "Browse...", width: 128, height: 1.0, tip: "Browse for game executable" do path = W3DHub.ask_file @game_path.value = path if !path.empty? && File.exist?(path) end diff --git a/lib/common.rb b/lib/common.rb index d2993ba..cdd88f0 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -147,26 +147,16 @@ class W3DHub end def self.ask_file(title: "Open File", filter: "*game*.exe") - if W3DHub.unix? - # search for command - cmds = %w{ zenity matedialog qarma kdialog } + result_ptr = LibUI.open_file(LIBUI_WINDOW) + result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") - command = cmds.find do |cmd| - cmd if system("which #{cmd}") - end + result + end - path = case File.basename(command) - when "zenity", "matedialog", "qarma" - `#{command} --file-selection --title "#{title}" --file-filter "#{filter}"` - when "kdialog" - `#{command} --title "#{title}" --getopenfilename . "#{filter}"` - else - raise "No known command found for system file selection dialog!" - end + def self.ask_folder(title: "Open Folder") + result_ptr = LibUI.open_folder(window) + result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") - path.strip - else - raise NotImplementedError - end + result end end diff --git a/lib/states/dialogs/import_game_dialog.rb b/lib/states/dialogs/import_game_dialog.rb index 1403dc7..68c2cbf 100644 --- a/lib/states/dialogs/import_game_dialog.rb +++ b/lib/states/dialogs/import_game_dialog.rb @@ -26,7 +26,7 @@ class W3DHub flow(width: 1.0, fill: true) do @game_path = edit_line "", fill: true, height: 1.0 - button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do + button "Browse...", width: 128, height: 1.0, tip: "Browse for game executable" do path = W3DHub.ask_file @game_path.value = path if !path.empty? && File.exist?(path) end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index a020ade..9918e7b 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -15,7 +15,6 @@ require "time" require "base64" require "zip" require "excon" -require "libui" class W3DHub W3DHUB_DEBUG = ARGV.join.include?("--debug") @@ -81,6 +80,15 @@ require "i18n" require "websocket-client-simple" require "English" require "sdl2" +require "libui" + +# Using a WHOLE ui library for: native file/folder open dialogs... +LibUI.init +LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0) +at_exit do + LibUI.control_destroy(LIBUI_WINDOW) + LibUI.uninit +end I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"] I18n.default_locale = :en