Exemple #1
0
//	Removes anything in `dirPath` (but not `dirPath` itself), except items whose `os.FileInfo.Name` matches any of the specified `keepNamePatterns`.
func ClearDirectory(dirPath string, keepNamePatterns ...string) (err error) {
	var fileInfos []os.FileInfo
	var matcher ustr.Matcher
	matcher.AddPatterns(keepNamePatterns...)
	if fileInfos, err = ioutil.ReadDir(dirPath); err == nil {
		for _, fi := range fileInfos {
			if fn := fi.Name(); !matcher.IsMatch(fn) {
				if err = os.RemoveAll(filepath.Join(dirPath, fn)); err != nil {
					return
				}
			}
		}
	}
	return
}
Exemple #2
0
//	Copies all files and directories inside `srcDirPath` to `dstDirPath`.
//	All sub-directories whose `os.FileInfo.Name` is matched by `skipDirs` (optional) are skipped.
func CopyAll(srcDirPath, dstDirPath string, skipDirs *ustr.Matcher) (err error) {
	var (
		srcPath, destPath string
		fileInfos         []os.FileInfo
	)
	if fileInfos, err = ioutil.ReadDir(srcDirPath); err == nil {
		EnsureDirExists(dstDirPath)
		for _, fi := range fileInfos {
			if srcPath, destPath = filepath.Join(srcDirPath, fi.Name()), filepath.Join(dstDirPath, fi.Name()); fi.IsDir() {
				if skipDirs == nil || !skipDirs.IsMatch(fi.Name()) {
					CopyAll(srcPath, destPath, skipDirs)
				}
			} else {
				CopyFile(srcPath, destPath)
			}
		}
	}
	return
}
Exemple #3
0
//	Toggles the nth (0-based) FxProc with the specified procID,
//	or all FxProcs with the specified procID if n < 0.
//	If me has no FxProc with the specified procID, appends a new one.
//	The procID must be one of the Core.Render.Fx.KnownProcIDs.
//	For this change to be applied, call FxEffect.UpdateRoutine() subsequently.
func (me *FxProcs) Toggle(procID string, n int) {
	var matcher ustr.Matcher
	matcher.AddPatterns(procID)
	idx, found, all := -1, false, n < 0
	for i := 0; i < len(*me); i++ {
		if matcher.IsMatch((*me)[i].procID) {
			if idx++; all || idx == n {
				(*me)[i].Toggle()
			}
			if found = true; !all {
				break
			}
		}
	}
	if (!found) && !matcher.HasWildcardPatterns() {
		*me = append(*me, FxProc{})
		(*me)[len(*me)-1].init(procID, idx+1)
	}
}