diff --git a/lib/getOS.lua b/lib/getOS.lua new file mode 100644 index 0000000..1a09a48 --- /dev/null +++ b/lib/getOS.lua @@ -0,0 +1,73 @@ +function getOS() + local raw_os_name, raw_arch_name = '', '' + + -- LuaJIT shortcut + if jit and jit.os and jit.arch then + raw_os_name = jit.os + raw_arch_name = jit.arch + else + -- is popen supported? + local popen_status, popen_result = pcall(io.popen, "") + if popen_status then + popen_result:close() + -- Unix-based OS + raw_os_name = io.popen('uname -s','r'):read('*l') + raw_arch_name = io.popen('uname -m','r'):read('*l') + else + -- Windows + local env_OS = os.getenv('OS') + local env_ARCH = os.getenv('PROCESSOR_ARCHITECTURE') + if env_OS and env_ARCH then + raw_os_name, raw_arch_name = env_OS, env_ARCH + end + end + end + + raw_os_name = (raw_os_name):lower() + raw_arch_name = (raw_arch_name):lower() + + local os_patterns = { + ['windows'] = 'Windows', + ['linux'] = 'Linux', + ['mac'] = 'Mac', + ['darwin'] = 'Mac', + ['^mingw'] = 'Windows', + ['^cygwin'] = 'Windows', + ['bsd$'] = 'BSD', + ['SunOS'] = 'Solaris', + } + + local arch_patterns = { + ['^x86$'] = 'x86', + ['i[%d]86'] = 'x86', + ['amd64'] = 'x86_64', + ['x86_64'] = 'x86_64', + ['Power Macintosh'] = 'powerpc', + ['^arm'] = 'arm', + ['^mips'] = 'mips', + } + + local os_name, arch_name = 'unknown', 'unknown' + + for pattern, name in pairs(os_patterns) do + if raw_os_name:match(pattern) then + os_name = name + break + end + end + for pattern, name in pairs(arch_patterns) do + if raw_arch_name:match(pattern) then + arch_name = name + break + end + end + return os_name, arch_name +end + +if select(1, ...) ~= 'os_name' then + print(("%q %q"):format(getOS())) +else + return { + getOS = getOS, + } +end diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..5b3bc8b --- /dev/null +++ b/settings.lua @@ -0,0 +1,4 @@ +settings = { + locale = 'RU' +} + diff --git a/start.lua b/start.lua index a8684f7..726749f 100755 --- a/start.lua +++ b/start.lua @@ -2,18 +2,29 @@ fl = require('moonfltk') lfs = require('lfs') +require('lib/getOS') +require('settings') + +OS = getOS() +print('Detected OS: ' .. OS) + +arg = {...} function to_pc(button) print(button:label()) if selected_device ~= '' then - os.execute('cp -rv '..selected_path..'/. '..local_dir) + if OS ~= 'Windows' then + os.execute('cp -rv '..selected_path..'/. '..local_dir) + end end end function to_phone(button) print(button:label()) if selected_device ~= '' then - os.execute('cp -rv '..local_dir..'/. '..selected_path) + if OS ~= 'Windows' then + os.execute('cp -rv '..local_dir..'/. '..selected_path) + end end end @@ -38,26 +49,28 @@ function refresh_devices() if win then if #phone_dir == 0 then - device_choice:clear() + device_choice:clear() device_choice:deactivate() to_pc_btn:deactivate() to_phone_btn:deactivate() else - device_choice:activate() - to_pc_btn:activate() - to_phone_btn:activate() + device_choice:activate() + to_pc_btn:activate() + to_phone_btn:activate() for i = 1, #phone_dir do device_choice:add(phone_dir[i]) end - end + end end end selected_device = '' selected_path = '' my_dir = lfs.currentdir() -local_dir = '/home/victoria/.config/StardewValley/Saves' -mount_point = '/run/user/1000/gvfs' +if OS ~= 'Windows' then + local_dir = settings.local_dir or '~/.config/StardewValley/Saves' + mount_point = '/run/user/1000/gvfs' +end W, H = 320, 360 @@ -72,12 +85,16 @@ bg_img = fl.png_image(my_dir..'/img/bg.png') bg_box = fl.box(1, 1, W, H) bg_box:image(bg_img) -title = fl.box(0, 10, W, 30, 'Выберите устройство:') +if OS ~= 'Windows' then + --fl.box(0, 20, W, 30, 'Точка монтирования:') + +end +fl.box(0, 70, W, 30, 'Выберите устройство:') refresh_img = fl.png_image(my_dir..'/img/refresh.png') -refresh_btn = fl.button(10, 50, 30, 30) +refresh_btn = fl.button(10, 100, 30, 30) refresh_btn:callback(refresh_devices) refresh_btn:image(refresh_img) -device_choice = fl.input_choice(50, 50, W-60, 30) +device_choice = fl.input_choice(50, 100, W-60, 30) device_choice:callback(input_choice_cb, device_choice) to_pc_btn = fl.button(50, H/2, W-100, 30, 'На ПК')