A simple dialog that allows you to browse and view configuration files.
// Configuration File Viewer /* */ pragma runLim, 0 DB dbMain = null DBE dbeConfFileTree = null DBE dbeFileContents = null DBE dbeSplitter = null const int AREA = 0 const int DIRECTORY = 1 const int FILE = 2 Icon ICON_CLOSED[] = { iconDatabase, iconFolder, iconFormal } Icon ICON_OPEN[] = { iconDatabase, iconFolderOpen, iconFormal } Regexp reConfUser = regexp2 "^confUser(.*)" Regexp reConfSystem = regexp2 "^confSystem(.*)" Regexp reConfSysUser = regexp2 "^confSysUser(.*)" Regexp reConfTemp = regexp2 "^confTemp(.*)" Skip confFileList = createString string selectedConfPath = "" int selectedType = AREA ConfType selectedConfType = null string selectedConfName = "" Buffer b = create /*********************** stringOf ***********************/ string stringOf(ConfType selectedConfType) { if (selectedConfType == confUser) return("confUser") if (selectedConfType == confSystem) return("confSystem") if (selectedConfType == confSysUser) return("confSysUser") if (selectedConfType == confTemp) return("confTemp") return("UNKNOWN") } /*********************** initialise skip list ***********************/ void initialiseSkipList(string dName, ConfType confArea, Skip skip) { string s = "" if (dName != "") { put(skip, dbSep stringOf(confArea) dbSep dName, DIRECTORY) } for s in confDirectory(dName, confArea) do { if (s == "." || s == "..") continue noError st = confRead(dName "\\" s, confArea) res = lastError if (!null res) { // error reading the file means it is a directory initialiseSkipList(s, confArea, skip) } else { put(skip, dbSep stringOf(confArea) dbSep (dName == "" ? "" : dName dbSep) s, FILE) close(st) } } } /*********************** initialise skip list ***********************/ void initialiseSkipList() { delete(confFileList) confFileList = createString initialiseSkipList("", confUser, confFileList) initialiseSkipList("", confSystem, confFileList) initialiseSkipList("", confSysUser, confFileList) initialiseSkipList("", confTemp, confFileList) } /*********************** initialise tree view ***********************/ void initialiseTreeView() { int i = 0 empty(dbeConfFileTree) insert(dbeConfFileTree, dbSep "confUser", ICON_CLOSED[AREA], ICON_OPEN[AREA]) insert(dbeConfFileTree, dbSep "confSystem", ICON_CLOSED[AREA], ICON_OPEN[AREA]) insert(dbeConfFileTree, dbSep "confSysUser", ICON_CLOSED[AREA], ICON_OPEN[AREA]) insert(dbeConfFileTree, dbSep "confTemp", ICON_CLOSED[AREA], ICON_OPEN[AREA]) for i in confFileList do { insert(dbeConfFileTree, (string key confFileList), ICON_CLOSED[i], ICON_OPEN[i]) } } /*********************** getConfNameAndType ***********************/ void getConfNameAndType() { if (reConfUser selectedConfPath) { selectedConfType = confUser selectedConfName = selectedConfPath[9:] } else if (reConfSystem selectedConfPath) { selectedConfType = confSystem selectedConfName = selectedConfPath[11:] } else if (reConfSysUser selectedConfPath) { selectedConfType = confSysUser selectedConfName = selectedConfPath[12:] } else if (reConfTemp selectedConfPath) { selectedConfType = confTemp selectedConfName = selectedConfPath[9:] } else { selectedConfType = null selectedConfName = "" } } /*********************** readConfFile ***********************/ string readConfFile() { ConfStream st = null string s = "" setempty(b) st = confRead(selectedConfName, selectedConfType) if (!null st) { while (true) { st >> s if (end st) break b += s "\n" } close(st) } return(stringOf(b)) } /*********************** refreshContents ***********************/ void refreshContents() { ConfType confArea = null selectedConfPath = get(dbeConfFileTree) getConfNameAndType() if (find(confFileList, dbSep selectedConfPath, selectedType) && selectedType == FILE) { set(dbeFileContents, readConfFile()) } else { set(dbeFileContents, "") } } /*********************** refreshTree ***********************/ void refreshTree() { initialiseSkipList() initialiseTreeView() } /*********************** doSelect ***********************/ void doSelect(DBE dbe) { refreshContents() } /*********************** doActivate ***********************/ void doActivate(DBE dbe) { doSelect(dbe) } /*********************** doExpand ***********************/ bool doExpand(DBE dbe, string s) { set(dbeConfFileTree, dbSep s) return(true) } /*********************** createDialog ***********************/ void createDialog() { dbMain = create(dbExplorer, "Configuration File Viewer") dbeConfFileTree = treeView(dbMain, treeViewOptionSorted, 300, 30) dbeConfFileTree->"right"->"unattached" dbeConfFileTree->"bottom"->"form" dbeConfFileTree->"left"->"form" dbeFileContents = text(dbMain, "", "", 550, 50, false) dbeFileContents->"left"->"unattached" dbeFileContents->"top"->"aligned"->dbeConfFileTree dbeFileContents->"bottom"->"form" dbeFileContents->"right"->"form" dbeSplitter = splitter(dbMain, dbeConfFileTree, dbeFileContents, 5) dbeSplitter->"top"->"aligned"->dbeConfFileTree dbeSplitter->"bottom"->"form" dbeSplitter->"left"->"unattached" dbeSplitter->"right"->"unattached" realize(dbMain) set(dbeConfFileTree, doSelect, doActivate) set(dbeConfFileTree, doExpand) refreshTree() show(dbMain) } /*********************** MAIN ***********************/ createDialog()
NEW!
A modified version of this script has been kindly provided by Peter Albert. This version handles nested directories.
View ConfigFileViewer_v2