Example #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
}
Example #2
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)
	}
}