ID:264935
 
Code:
            var/game = input("Enter game path","Game") as text
game = game + "/"
var/list/added_files = list()
var/list/checked = list()
var/path = game
var/opath = game

checking

for(var/v in flist("[path]"))

if(added_files.Find(v)||checked.Find(v))
continue




if(copytext(v,length(v),length(v)+1)=="/")

checked+=v
v = copytext(v,1,length(v))
path = "[path][v]"
goto checking

if(findtext(v,".dmb")==0&&findtext(v,".rsc")==0&&findtext(v,".txt")==0&&findtext(v,".sav")==0)
alert("You are attempting to upload an unauthorized file,[v], please consult our Terms of Use page to see which files may be uploaded onto our server, thank you!")
return
else
added_files += v
if(!(added_files.Find("[game_name].dmb"))||!(added_files.Find("[game_name].rsc")))
//if(!(findtext(v,".dmb"))||!(findtext(v,".rsc")))
alert("You either forgot to add the .dmb file or the .rsc file, which are key files, please try again!")
return


Problem description:
im using this batch of code to indentity a given path on a users computer which contains his game files which will later be uploaded to the server.
Now first im scanning to see what kind of files the user is trying to upload to make sure that their only game related files(.dmb,.rsc,.sav etc) but for some reason if the user is trying to upload say file called "savefiles/" and inside it theres another file and inside it another file it will not scan the contents of the third file.

Help anyone?


bump, please i really need help with this!!!
Remove the
game = game + "/"

what that does is it add another / after the selected folder, making it think it should search inside the last path.
that would make it unopenable. and i really hope when you set the path, you type like this:
/1st-folder/2nd-folder/Pathfile.dm

remembering the first slash.


If that doesnt work, try this:

var/inp = input("Enter game path","Game") as text
var/game = "/" + inp
//Now you dont have to set the first slash.
Biond_coder wrote:
Problem description:
Now first im scanning to see what kind of files the user is trying to upload

Well, take note that this only scans files on the host's computer. Just a heads-up.

to make sure that their only game related files(.dmb,.rsc,.sav etc) but for some reason if the user is trying to upload say file called "savefiles/" and inside it theres another file and inside it another file it will not scan the contents of the third file.

The problem you're experiencing stems from this segment:

Code:
>           checking
>
> for(var/v in flist("[path]"))
>
> if(added_files.Find(v)||checked.Find(v))
> continue
>
>
>
>
> if(copytext(v,length(v),length(v)+1)=="/")
>
> checked+=v
> v = copytext(v,1,length(v))
> path = "[path][v]"
> goto checking


Notably, the line v = copytext(v,1,length(v))...which only serves one function: it strips the trailing "/" and directly causes the problem that you're experiencing, since flist("savefiles/foo") does not equal flist("savefiles/foo/"). In fixing this, you'll also need to take out the pointless game = game + "/" line, as well.

Note that there are a myriad of other errors in your code snippet, many of which stem from your design decision to use goto. Instead, you should opt for splitting the function into multiple procs and employing recursion. As a brief example:
proc/can_upload(fname)
var/static/list/approved = list(".dmb",".rsc",".txt",".sav")
var/i // index of "."
for(i=length(fname), i>0, --i)
if(text2ascii(fname, i) == 0x2E) // == "."
break
if(approved.Find(lowertext(copytext(fname, i))))
return TRUE // can upload!

proc/check_path(p)
var/list/added_files = new
for(var/v in flist(p))
if(ascii2text(text2ascii(v, length(v))) == "/") // I prefer this method over copytext()
added_files += check_path(p+v)
else if(can_upload(v))
added_files += (p+v)
return added_files


check_path() returns a list of files that are acceptable.