diff --git a/hooks/post_install.lua b/hooks/post_install.lua index 3c9ffd5..4549001 100644 --- a/hooks/post_install.lua +++ b/hooks/post_install.lua @@ -24,26 +24,46 @@ function PLUGIN:PostInstall(ctx) -- So we need to reorganize: move rootPath/* to rootPath/cmdline-tools/VERSION/ local temp_path = root_path .. "-temp" - local target_path = file.join_path(root_path, "cmdline-tools", version) + local parent_path = file.join_path(root_path, "cmdline-tools") + local target_path = file.join_path(parent_path, version) - -- Move current rootPath to temp location - os.execute("mv " .. root_path .. " " .. temp_path) + -- Cross-platform file operations (works on Unix and Windows) + local win = RUNTIME.osType == "windows" + local cmd = require("cmd") - -- Recreate rootPath with proper structure - os.execute("mkdir -p " .. target_path) + -- Move current rootPath to temp location + if win then + local systemroot = os.getenv("SystemRoot") or "C:\\Windows" + cmd.exec('move "' .. root_path .. '" "' .. temp_path .. '"', {cwd = systemroot}) + else + cmd.exec('mv "' .. root_path .. '" "' .. temp_path .. '"') + end - -- Move contents from temp to target - os.execute("mv " .. temp_path .. "/* " .. target_path .. "/") + -- Recreate parent_path with proper structure + if win then + local systemroot = os.getenv("SystemRoot") or "C:\\Windows" + cmd.exec('mkdir "' .. parent_path .. '"', {cwd = systemroot}) + else + cmd.exec('mkdir -p "' .. parent_path .. '"') + end - -- Clean up temp - os.execute("rm -rf " .. temp_path) + -- Move temp to target + if win then + local systemroot = os.getenv("SystemRoot") or "C:\\Windows" + cmd.exec('move "' .. temp_path .. '" "' .. target_path .. '"', {cwd = systemroot}) + else + cmd.exec('mv "' .. temp_path .. '" "' .. target_path .. '"') + end -- Verify installation - local sdkmanager_path = file.join_path(target_path, "bin", "sdkmanager") + local ext = win and ".bat" or "" + local sdkmanager_path = file.join_path(target_path, "bin", "sdkmanager" .. ext) if not file.exists(sdkmanager_path) then error("Installation verification failed: sdkmanager not found at " .. sdkmanager_path) end -- Make sure binaries are executable (for Unix systems) - os.execute("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true") + if not win then + cmd.exec("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true") + end end