public Worker(GUIIface gui, Project p) { this.p = p; Parser = new LuaHTMLParser(gui, p); Writer = new FileWriter(p); Progress.PropertyChanged += new PropertyChangedEventHandler(Progress_PropertyChanged); }
public FileWriter(Project p) { this.p = p; }
private void SetProject(Project p) { if (workers != null && workers.IsRunning) throw new InvalidOperationException("Cannot load a new project into the program context while the current project is running."); if (IsProjectLoaded) SaveProject(); project = p; workers = new Workers(project, gui); NotifyPropertyChanged("IsProjectLoaded"); NotifyPropertyChanged("Project"); NotifyPropertyChanged("Workers"); }
public LuaHTMLParser(GUIIface gui, Project p) { this.p = p; this.gui = gui; /* string pkgpath = (string)lua["package.path"]; if (pkgpath == null) pkgpath = ""; pkgpath += ";" + System.Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "lualibs" + System.IO.Path.DirectorySeparatorChar + "?.lua"; lua["package.path"] = pkgpath; */ lua["project"] = new ProjectInterfaceToLua(p); lua["queue"] = new QueueInterfaceToLua(p, this); lua["util"] = new UtilInterfaceToLua(); lua.RegisterFunction("log", this, this.GetType().GetMethod("log")); lua.RegisterFunction("io.canwrite", this, this.GetType().GetMethod("CanWrite")); lua.RegisterFunction("io.ensurefolder", this, this.GetType().GetMethod("EnsureFolder")); lua.RegisterFunction("io.movefile", this, this.GetType().GetMethod("MoveFile")); lua.DoString(@" io.popen = function(prog, mode) error('Opening processes is disabled.') end do local realioopen = io.open local realioclose = io.close local ensurefolder = io.ensurefolder local movefile = io.movefile io.ensurefolder = nil local openfilenames = {} io.openfordl = function(filen, mode) filen = filen:gsub('/','\\') if filen:match('^\\') or filen:match('%.%.\\') or filen:match('^%w:') then error('Only relative paths that do not go up (..) are allowed') end filen = project.DownloadFolder .. '\\' .. filen ensurefolder(filen) if not io.canwrite(filen) then return nil, 'Cannot open file due to user settings.' end local tmpfilen = filen .. '.dlprog_part' local f,err = realioopen(tmpfilen,mode) if f then openfilenames[f] = filen end return f,err end io.open = function(filen, mode) filen = filen:gsub('/','\\') if filen:match('^\\') or filen:match('%.%.\\') or filen:match('^%w:') then error('Only relative paths that do not go up (..) are allowed') end filen = project.DownloadFolder .. '\\' .. filen ensurefolder(filen) return realioopen(filen,mode) end io.close = function(file) local ret = realioclose(file) local filen = openfilenames[file] if filen then movefile(filen .. '.dlprog_part',filen) openfilenames[file] = nil end return ret end end "); }
public QueueInterfaceToLua(Project p, LuaHTMLParser h) { this.p = p; this.h = h; }
public ProjectInterfaceToLua(Project p) { DownloadFolder = p.RootDirectory; }
public Workers(Project p, GUIIface gui) { this.p = p; this.gui = gui; }