mirror of
https://github.com/wiremod/advdupe2.git
synced 2025-03-04 03:03:05 -05:00
Add AdvDupe2.SanitizeFilename (#480)
* Add AdvDupe2.SanitizeFilename * Uncomment * Style
This commit is contained in:
parent
0ff4d3046c
commit
8a1fa8658f
@ -1,3 +1,13 @@
|
|||||||
|
local invalidCharacters = { "\"", ":"}
|
||||||
|
function AdvDupe2.SanitizeFilename(filename)
|
||||||
|
for i=1, #invalidCharacters do
|
||||||
|
filename = string.gsub(filename, invalidCharacters[i], "_")
|
||||||
|
end
|
||||||
|
filename = string.gsub(filename, "%s+", " ")
|
||||||
|
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
|
||||||
local function AdvDupe2_ReceiveFile(len, ply)
|
local function AdvDupe2_ReceiveFile(len, ply)
|
||||||
local AutoSave = net.ReadUInt(8) == 1
|
local AutoSave = net.ReadUInt(8) == 1
|
||||||
|
|
||||||
@ -18,6 +28,7 @@ local function AdvDupe2_ReceiveFile(len, ply)
|
|||||||
path = AdvDupe2.GetFilename(AdvDupe2.SavePath)
|
path = AdvDupe2.GetFilename(AdvDupe2.SavePath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
path = AdvDupe2.SanitizeFilename(path)
|
||||||
local dupefile = file.Open(path, "wb", "DATA")
|
local dupefile = file.Open(path, "wb", "DATA")
|
||||||
if(!dupefile)then
|
if(!dupefile)then
|
||||||
AdvDupe2.Notify("File was not saved!",NOTIFY_ERROR,5)
|
AdvDupe2.Notify("File was not saved!",NOTIFY_ERROR,5)
|
||||||
|
@ -306,6 +306,8 @@ local function RenameFileCl(node, name)
|
|||||||
AdvDupe2.Notify("Rename limit exceeded, could not rename.", NOTIFY_ERROR)
|
AdvDupe2.Notify("Rename limit exceeded, could not rename.", NOTIFY_ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
FilePath = AdvDupe2.SanitizeFilename(FilePath)
|
||||||
file.Write(FilePath, File)
|
file.Write(FilePath, File)
|
||||||
if (file.Exists(FilePath, "DATA")) then
|
if (file.Exists(FilePath, "DATA")) then
|
||||||
file.Delete(tempFilePath .. ".txt")
|
file.Delete(tempFilePath .. ".txt")
|
||||||
|
@ -524,6 +524,8 @@ if CLIENT then
|
|||||||
local readFileName = "advdupe2/"..arg[1]
|
local readFileName = "advdupe2/"..arg[1]
|
||||||
local writeFileName = "advdupe2/"..string.StripExtension(arg[1])..".json"
|
local writeFileName = "advdupe2/"..string.StripExtension(arg[1])..".json"
|
||||||
|
|
||||||
|
writeFileName = AdvDupe2.SanitizeFilename(writeFileName)
|
||||||
|
|
||||||
local readFile = file.Open(readFileName, "rb", "DATA")
|
local readFile = file.Open(readFileName, "rb", "DATA")
|
||||||
if not readFile then print("File could not be read or found! ("..readFileName..")") return end
|
if not readFile then print("File could not be read or found! ("..readFileName..")") return end
|
||||||
local readData = readFile:Read(readFile:Size())
|
local readData = readFile:Read(readFile:Size())
|
||||||
|
Loading…
Reference in New Issue
Block a user