/client/proc/getAllCodeFiles(var/file as file)
set name = "USE THIS ONE"
set category = "Admin"
var/list/files = list()
var/text = file2text(file)
var/regex/r1 = regex("^#include \"(.*)\"$", "gm")
var/regex/r2 = regex("\\.dm$", "g")
while(r1.Find(text))
if(r2.Find(r1.group[0])) files += r1.group[0]
for(var/f in files)
fcopy(f, "shittocheckout.txt")
getAllUsedIcons("shittocheckout.txt")
/client/proc/getAllUsedIcons(var/file as file)
set name = "OR THIS ONE"
set category = "Admin"
var/list/iconsUsed = list()
var/text = file2text(file)
var/regex/r1 = regex("^\\s*?icon_state = \"(.*?)\"$", "gm")
while(r1.Find(text))
if(!iconsUsed.Find(r1.group[0])) iconsUsed += r1.group[0]
world << iconsUsed
Problem description:
I'm trying to get a list of every single icon in the code. To do so, I figured if I could get all of the code files into the same txt file, then I could search through them with a regex and get a list of what I've got, but for some reason the r1.Find() under getAllCodeFiles() only executes once and does nothing (known by using the profiler, only one instance of /regex/Find() when the code is called). What's wrong or what is a better way to do what I'm doing?
I'm not entirely sure what your desired end result is, and I'm not too familiar with regular expressions; so I just outright scripted something different as opposed to try and find what was causing your existing code errors.
As for whether this is the best method, it's doubtful. However, what this will do is scan your base folder (didn't feel like branching into other subfolders) for .dm files. It will then search the .dm files for the file flag ' ', and if it determines it is indeed an image file (dmi, bmp, png, gif) it will store the icon in a list and then output the list contents.
There are two verb's here. ScanFiles and ScanFiles2. The only difference is ScanFiles only tells you which files are being used, while ScanFiles2 tells you how many times. As stated, I don't really know what your end result is suppose to be.
I put some comments in the code, but their haphazard due to me being a tad bit tired. I do hope this helps you in some way though.
Oh, as a side note, this will only work if the server running it is from the source code. Meaning, in the server's root directory, you can find the scripts.