With Windows I've ran in a lot of problems when trying to compile my application for distribution, but most of them were fixable. This problem might not be.
I've got a drag and drop system in my application where customers can drop a .bin file to be uploaded to a microcontroller so they can update the device. The application also contains a driver installer to communicate with the microcontroller. The output of the CMD gets read and human readable messages are saved in a log derived from the CMD. The problem is, to install the drivers the application needs admin privileges which I fixed in another post with the help of some amazing people. The thing is, when running apps in admin mode on Windows, drag 'n drop is blocked from explorer.exe to your app.exe since explorer.exe isn't admin by default and isn't allowed to drop the file in your application so love2d's callback for filedropped won't notice.
I've tried a lot of things including only running the driver installer commands as admin which doesn't work since for that I would need to start a new powershell window inside the os.execute with admin privileges meaning I can't read from that window with handle = io.popen.
So the request is to please implement a function to read the path of an actual file you have copied. I know there's the option to read the contents of the clipboard with text, but not from a file. And for users to right click on the binary file, then copy the path, and name, merge it together in notepad and then copy the complete string is a no go. Also the same reason I don't want to add a file input text field.
By the way, this is some test code I got from ChatGPT using ffi, since this stuff is so far above my head, I can't program it myself. It could actually detect a file but it was garbled data:
Code: Select all
local ffi = require("ffi")
ffi.cdef[[
typedef const char* LPCSTR;
typedef int BOOL;
typedef void* HANDLE;
BOOL OpenClipboard(void* hWnd);
BOOL CloseClipboard();
BOOL IsClipboardFormatAvailable(int format);
HANDLE GetClipboardData(int format);
void* GlobalLock(HANDLE hMem);
void GlobalUnlock(HANDLE hMem);
HANDLE GlobalAlloc(int uFlags, size_t dwBytes);
size_t GlobalSize(HANDLE hMem);
int GetLastError();
]]
-- Clipboard format for file data
local CF_HDROP = 15
local user32 = ffi.load("user32")
local kernel32 = ffi.load("kernel32")
function getClipboardFilePath()
if user32.OpenClipboard(nil) ~= 0 then
-- Check if the clipboard contains file paths
if user32.IsClipboardFormatAvailable(CF_HDROP) ~= 0 then
local hMem = user32.GetClipboardData(CF_HDROP)
local pMem = kernel32.GlobalLock(hMem)
-- Extract the file path (the first file in the list)
local filePath = ffi.string(pMem)
kernel32.GlobalUnlock(hMem)
user32.CloseClipboard()
return filePath
end
user32.CloseClipboard()
end
return nil
end