XJMLN Posted February 6, 2018 Share Posted February 6, 2018 Hi, I tried to use fileOpen (c-side) when downloadFile is started, but it doesn't work in db3: Bad usage @ 'fileOpen' [unable to load file 'dff/vehicles/542.dff'] etc. but file is in this dir. Someone maybe know where problem is? function replac_getAllSize(d) local size = 0 for i,v in ipairs(d) do local t local t2 if v[2] == 1 then t = "txd/vehicles/"..v[1]..".txd" t2 = "dff/vehicles/"..v[1]..".dff" elseif v[2] == 2 then t = "txd/skins/"..v[1]..".txd" t2 = "dff/skins/"..v[1]..".dff" end if fileExists(t2) then local openFile = fileOpen(t2,true) if openFile then size = size + fileGetSize(openFile) fileClose(openFile) else end else end if fileExists(t) then local openFile2 = fileOpen(t,true) if openFile2 then size = size + fileGetSize(openFile2) fileClose(openFile2) else end else end end return size/1048576 end function calcProg(w, p) if w and p then local w = w -2 local width = ((w*p)/100) return width end return 0 end function replac_render() if (not r.rendered) then return end local size = replac_getAllSize(r.installed) dxDrawRectangle(224, 512, 362, 36, tocolor(0, 0, 0, 209), false) dxDrawRectangle(230, 517, 350, 25, tocolor(255, 255, 255, 255), false) local progress = ((size*100)/r.sizeAll) local x,y,w,h = (230/800)*sw, (517/600)*sh, (350/800)*sw, (25/600)*sh local width = calcProg(w,progress) dxDrawRectangle(x,y,width,h, tocolor(104, 215, 89, 255), false) dxDrawText("Trwa pobieranie "..string.format("%.02f",size).."MB/"..string.format("%.02f",r.sizeAll).."MB.. ("..math.floor(progress).."%)", 230, 517, 580, 542, tocolor(0, 0, 0, 254), 1.00, "clear", "center", "center", false, false, false, false, false) end function replac_applyChanges(installed,uninstalled) r.rendered = true r.sizeAll = 0 for i,v in ipairs(installed) do if v[2] == 1 then t = "vehicles" elseif v[2] == 2 then t = "skins" end r.sizeAll = r.sizeAll + v[3] local txd = downloadFile("txd/"..t.."/"..v[1]..".txd") local dff = downloadFile("dff/"..t.."/"..v[1]..".dff") end r.installed = installed addEventHandler("onClientRender",root,replac_render) end Link to comment
NeXuS™ Posted February 7, 2018 Share Posted February 7, 2018 Why do you want to open the TXDs and DFFs? Link to comment
XJMLN Posted February 7, 2018 Author Share Posted February 7, 2018 Really? Just look in the code, lol but ok, I must open file to get the actual size of it. Link to comment
NeXuS™ Posted February 7, 2018 Share Posted February 7, 2018 Try renaming it to .txt and opening it. I don't know if it's going to work. Link to comment
XJMLN Posted February 7, 2018 Author Share Posted February 7, 2018 I can't rename file while downloading it in the same time Link to comment
NeXuS™ Posted February 7, 2018 Share Posted February 7, 2018 Give me 10 minutes to test a way. Link to comment
NeXuS™ Posted February 7, 2018 Share Posted February 7, 2018 So the only way I could work around is creating a server-sided script. On startUp calculating the filesizes, saving it into a variable. Then whenever the client joins, the client-side requests that variable (via events). If you need an example of the script. local fileList = {"test.dff"} local allSizes = 0 function calcAll() for i, k in pairs(fileList) do if fileExists(k) then allSizes = allSizes + fileGetSize(fileOpen(k)) end end end calcAll() function requestAll(requestClient) triggerClientEvent(requestClient, "startDownload", root, allSizes) end addEvent("requestSize", true) addEventHandler("requestSize", root, requestAll) local fileList = {"test.dff"} function startDownload(fileSizes) outputChatBox("All size: " .. fileSizes) for i, k in pairs(fileList) do downloadFile(k) end end addEvent("startDownload", true) addEventHandler("startDownload", root, startDownload) triggerServerEvent("requestSize", root, localPlayer) Link to comment
XJMLN Posted February 7, 2018 Author Share Posted February 7, 2018 (edited) Yup, i use that version to get size of file on server , but now i need size from client file to show something like 60MB/120MB (50%). It's something weird because i use (probably) the same method from this resource and in that resource it works perfectly.. Edited February 7, 2018 by XJMLN Link to comment
NeXuS™ Posted February 7, 2018 Share Posted February 7, 2018 What you could do is: Using the onClientFileDownloadComplete event, creating an average download speed, and using that to determine how long it'll take to download the next files. (After the first file downloaded the progress would jump from 0MB to xMB, but thats the only way I can think now.) Link to comment
XJMLN Posted February 7, 2018 Author Share Posted February 7, 2018 (edited) I can't do anything with that it's caused by that: https://bugs.mtasa.com/view.php?id=3168 Close please. Edited February 7, 2018 by XJMLN Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now