Skip to content
56 changes: 37 additions & 19 deletions lua/advdupe2/cl_file.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
function AdvDupe2.GetFilename(path, overwrite)
path = AdvDupe2.SanitizeFilename(path)
if not overwrite and file.Exists(path .. ".txt", "DATA") then
for i = 1, AdvDupe2.FileRenameTryLimit do
local p = string.format("%s_%03d.txt", path, i)
if not file.Exists(p, "DATA") then
return p
end
end
return false
end
return path .. ".txt"
end

function AdvDupe2.ReceiveFile(data, autoSave)
AdvDupe2.RemoveProgressBar()
if not data then
Expand Down Expand Up @@ -42,24 +56,28 @@ function AdvDupe2.ReceiveFile(data, autoSave)
end

local filename = string.StripExtension(string.GetFileFromFilename( path ))

local Browser = AdvDupe2.FileBrowser.Browser

if autoSave then
if(IsValid(AdvDupe2.FileBrowser.AutoSaveNode))then
if IsValid(AdvDupe2.FileBrowser.AutoSaveNode) then
local add = true
for i=1, #AdvDupe2.FileBrowser.AutoSaveNode.Files do
if(filename==AdvDupe2.FileBrowser.AutoSaveNode.Files[i].Label:GetText())then
add=false
for i = 1, #AdvDupe2.FileBrowser.AutoSaveNode.Files do
if filename == AdvDupe2.FileBrowser.AutoSaveNode.Files[i].Label:GetText() then
add = false
break
end
end
if(add)then
AdvDupe2.FileBrowser.AutoSaveNode:AddFile(filename)
AdvDupe2.FileBrowser.Browser.pnlCanvas:Sort(AdvDupe2.FileBrowser.AutoSaveNode)
if add then
error "Not implemented yet"
-- AutoSaveNode:AddFile(filename)
-- Browser.pnlCanvas:Sort(AdvDupe2.FileBrowser.AutoSaveNode)
end
end
else
AdvDupe2.FileBrowser.Browser.pnlCanvas.ActionNode:AddFile(filename)
AdvDupe2.FileBrowser.Browser.pnlCanvas:Sort(AdvDupe2.FileBrowser.Browser.pnlCanvas.ActionNode)
Browser:IncomingFile(path, path)
end

if not errored then
AdvDupe2.Notify("File successfully saved!",NOTIFY_GENERIC, 5)
end
Expand Down Expand Up @@ -89,7 +107,7 @@ end

local MAX_UPLOAD_ATTEMPTS = 3
function AdvDupe2.UploadFile(ReadPath, ReadArea)
if AdvDupe2.Uploading then
if AdvDupe2.Uploading then
AdvDupe2.UploadAttempts = AdvDupe2.UploadAttempts + 1
if AdvDupe2.UploadAttempts < MAX_UPLOAD_ATTEMPTS then
local remaining = MAX_UPLOAD_ATTEMPTS - AdvDupe2.UploadAttempts
Expand All @@ -100,15 +118,15 @@ function AdvDupe2.UploadFile(ReadPath, ReadArea)
AdvDupe2.Uploading:Remove() -- kill upload netstream
AdvDupe2.ClearFileUpload()
end
if(ReadArea==0)then
ReadPath = AdvDupe2.DataFolder.."/"..ReadPath..".txt"
elseif(ReadArea==1)then
ReadPath = AdvDupe2.DataFolder.."/-Public-/"..ReadPath..".txt"
if ReadArea == AdvDupe2.AREA_ADVDUPE2 then
ReadPath = AdvDupe2.DataFolder .. "/" .. ReadPath .. ".txt"
elseif ReadArea == AdvDupe2.AREA_PUBLIC then
ReadPath = AdvDupe2.DataFolder .. "/-Public-/" .. ReadPath .. ".txt"
else
ReadPath = "adv_duplicator/"..ReadPath..".txt"
ReadPath = "adv_duplicator/" .. ReadPath .. ".txt"
end

if(not file.Exists(ReadPath, "DATA"))then AdvDupe2.Notify("File does not exist", NOTIFY_ERROR) return end
if not file.Exists(ReadPath, "DATA") then AdvDupe2.Notify("File does not exist", NOTIFY_ERROR) return end

local read = file.Read(ReadPath)
if not read then AdvDupe2.Notify("File could not be read", NOTIFY_ERROR) return end
Expand All @@ -117,11 +135,11 @@ function AdvDupe2.UploadFile(ReadPath, ReadArea)
name = string.sub(name, 1, #name-4)

local success, dupe, info, moreinfo = AdvDupe2.Decode(read)
if(success)then
if success then
AdvDupe2.SendFile(name, read)

AdvDupe2.LoadGhosts(dupe, info, moreinfo, name)
else
AdvDupe2.Notify("File could not be decoded. ("..dupe..") Upload Canceled.", NOTIFY_ERROR)
AdvDupe2.Notify("File could not be decoded. (" .. dupe .. ") Upload Canceled.", NOTIFY_ERROR)
end
end
end
Loading
Loading