當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.IsFileExist函數代碼示例

本文整理匯總了Golang中pkg/linuxdeepin/com/lib/utils.IsFileExist函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsFileExist函數的具體用法?Golang IsFileExist怎麽用?Golang IsFileExist使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IsFileExist函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getThemePreview

func (t *Theme) getThemePreview(themeType string) string {
	var target string
	switch themeType {
	case "gtk":
		target = path.Join("WindowThemes", t.GtkTheme)
	case "icon":
		target = path.Join("IconThemes", t.IconTheme)
	case "cursor":
		target = path.Join("CursorThemes", t.CursorTheme)
	}

	filename := path.Join(os.Getenv("HOME"), userPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	filename = path.Join(systemPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	return ""
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:25,代碼來源:theme.go

示例2: copyBroswerConfig

// Default broswer: google-chrome
func copyBroswerConfig(home, lang string) error {
	dest := path.Join(home, ".config/google-chrome")
	if dutils.IsFileExist(dest) {
		return nil
	}

	var (
		override   = "/usr/share/deepin-default-settings/google-chrome/override-chrome-config.tar"
		configLang = fmt.Sprintf("/usr/share/deepin-default-settings/google-chrome/chrome-config-%s.tar", lang)
		config     = "/usr/share/deepin-default-settings/google-chrome/chrome-config.tar"

		broswerConfig string
	)
	switch {
	case dutils.IsFileExist(override):
		broswerConfig = override
	case dutils.IsFileExist(configLang):
		broswerConfig = configLang
	case dutils.IsFileExist(config):
		broswerConfig = config
	}
	if len(broswerConfig) == 0 {
		return fmt.Errorf("Not found broswer configure file")
	}

	_, err := archive.Extracte(broswerConfig, path.Join(home, ".config"))
	return err
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:29,代碼來源:config_datas.go

示例3: renameXDGDirs

func renameXDGDirs(home, lang string) {
	var (
		desktop   = path.Join(home, "Desktop")
		templates = path.Join(home, "Templates")
	)

	switch lang {
	case "zh_CN":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌麵"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			//dutils.CreateFile(path.Join(home, "模板", "文本文件"))
		}
	case "zh_TW":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌麵"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			dutils.CreateFile(path.Join(home, "模板", "新增檔案"))
		}
	default:
		if dutils.IsFileExist(templates) {
			dutils.CreateFile(path.Join(templates, "New file"))
		}
	}
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:31,代碼來源:config_datas.go

示例4: modifyCustomTheme

func (m *Manager) modifyCustomTheme(info *Theme) bool {
	homeDir := dutils.GetHomeDir()
	dir := path.Join(homeDir, userThemePath, "Custom")
	if !dutils.IsFileExist(dir) {
		err := os.MkdirAll(dir, dirPermMode)
		if err != nil {
			logger.Debug(err)
			return false
		}
	}

	filename := path.Join(dir, "theme.ini")
	var newFile bool
	if !dutils.IsFileExist(filename) {
		err := dutils.CopyFile(tempDThemeCustom, filename)
		if err != nil {
			logger.Debug(err)
			return false
		}
		newFile = true
	}

	kFile := glib.NewKeyFile()
	defer kFile.Free()
	_, err := kFile.LoadFromFile(filename,
		glib.KeyFileFlagsKeepComments|
			glib.KeyFileFlagsKeepTranslations)
	if err != nil {
		return false
	}

	kFile.SetString(groupKeyComponent, themeKeyGtk, info.GtkTheme)
	kFile.SetString(groupKeyComponent, themeKeyIcon, info.IconTheme)
	kFile.SetString(groupKeyComponent, themeKeyCursor, info.CursorTheme)
	kFile.SetString(groupKeyComponent, themeKeySound, info.SoundTheme)
	kFile.SetString(groupKeyComponent, themeKeyBackground, info.Background)
	kFile.SetString(groupKeyComponent, themeKeyFontName, info.FontName)
	kFile.SetString(groupKeyComponent, themeKeyFontMono, info.FontMono)
	kFile.SetInteger(groupKeyComponent, themeKeyFontSize, info.FontSize)

	_, contents, err := kFile.ToData()
	if err != nil {
		return false
	}

	m.wLocker.Lock()
	defer m.wLocker.Unlock()
	ok := dutils.WriteStringToKeyFile(filename, contents)
	if newFile && ok {
		touchFile()
	}

	return ok
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:54,代碼來源:deepin_theme.go

示例5: doGenCursorThumb

func doGenCursorThumb(forceFlag bool, outDir string) {
	list := getCursorList()
	for _, l := range list {
		dest := getThumbCachePath("--cursor", l.Path, outDir)
		if len(dest) < 1 || (!forceFlag && dutils.IsFileExist(dest)) {
			continue
		}
		bg := getThumbBg()
		if !genCursorThumbnail(l, dest, bg) {
			logger.Debugf("ERROR: Generate Cursor Thumbnail\n")
		}
	}
	if dutils.IsFileExist(XCUR2PNG_OUTDIR) {
		os.RemoveAll(XCUR2PNG_OUTDIR)
	}
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:16,代碼來源:main.go

示例6: getCPUInfoFromFile

func getCPUInfoFromFile(config string) (string, error) {
	if !dutils.IsFileExist(config) {
		return "", errFileNotExist
	}

	contents, err := ioutil.ReadFile(config)
	if err != nil {
		return "", err
	}

	var (
		info string
		cnt  int
	)
	lines := strings.Split(string(contents), "\n")
	for _, line := range lines {
		if strings.Contains(line, "model name") {
			vars := strings.Split(line, ":")
			if len(vars) != 2 {
				break
			}
			cnt++
			if len(info) == 0 {
				info += vars[1]
			}
		}
	}
	if cnt > 1 {
		info = fmt.Sprintf("%s x %v", info, cnt)
	}

	return strings.TrimSpace(info), nil
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:33,代碼來源:system_info.go

示例7: getDscConfInfo

func getDscConfInfo() (isUpdate bool, duration int32) {
	isUpdate = true
	duration = 3

	homeDir := dutils.GetHomeDir()
	filename := path.Join(homeDir, DSC_CONFIG_PATH)
	if !dutils.IsFileExist(filename) {
		return
	}

	str, _ := dutils.ReadKeyFromKeyFile(filename,
		"update", "auto", "")
	if v, ok := str.(string); ok && v == "False" {
		isUpdate = false
	}

	interval, ok1 := dutils.ReadKeyFromKeyFile(filename,
		"update", "interval", int32(0))
	if ok1 {
		if i, ok := interval.(int32); ok {
			duration = int32(i)
		}
	}

	return

}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:27,代碼來源:dsc.go

示例8: Set

func (bg *Background) Set(uri string) error {
	settings := NewGSettings("com.deepin.wrap.gnome.desktop.background")
	defer Unref(settings)

	value := settings.GetString(settingsKeyPictureURI)
	if isBackgroundSame(uri, value) {
		return nil
	}

	if isBackgroundInInfoList(uri, bg.infoList) {
		settings.SetString(settingsKeyPictureURI, uri)
		return nil
	}

	// cp uri to user wallpapers
	src := dutils.DecodeURI(uri)
	if !dutils.IsFileExist(src) {
		src = defaultBgFile
	}
	dir := getUserWallpaper()
	if len(dir) == 0 {
		return errUserPict
	}

	filename := path.Join(dir, path.Base(src))
	err := dutils.CopyFile(src, filename)
	if err != nil {
		return err
	}
	settings.SetString(settingsKeyPictureURI,
		dutils.EncodeURI(filename, dutils.SCHEME_FILE))

	return nil
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:34,代碼來源:background.go

示例9: isVersionSame

func isVersionSame() bool {
	versionFile := path.Join(THUMB_CACHE_SYS_PATH, VERSION_FILE)
	if !dutils.IsFileExist(versionFile) {
		err := writeVersionFile(versionFile)
		if err != nil {
			logger.Warning("writeVersionFile failed:", err)
		}
		return false
	}

	contents, err := ioutil.ReadFile(versionFile)
	if err != nil {
		logger.Warning("Read version file failed:", err)
		return false
	}

	if string(contents) == VERSION {
		return true
	}
	if err := writeVersionFile(versionFile); err != nil {
		logger.Warning("writeVersionFile failed:", err)
	}

	return false
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:25,代碼來源:check_version.go

示例10: getPngList

func getPngList(dir string) []string {
	list := []string{}

	if !dutils.IsFileExist(dir) {
		return list
	}

	fp, err := os.Open(dir)
	if err != nil {
		return list
	}
	defer fp.Close()

	names, err1 := fp.Readdirnames(0)
	if err1 != nil {
		return list
	}

	for _, n := range names {
		ok, _ := regexp.MatchString(`\.png$`, n)
		if !ok {
			continue
		}

		filename := path.Join(dir, n)
		list = append(list, filename)
	}

	return list
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:30,代碼來源:icon.go

示例11: searchString

func searchString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	matchers := getMatchers(key)
	var matchRes = matchResInfo{}
	for _, v := range datas {
		getMatchReuslt(&v, matchers, &matchRes)
	}

	list = sortMatchResult(&matchRes)

	return list
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:28,代碼來源:search.go

示例12: searchStartWithString

func searchStartWithString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	match := regexp.MustCompile(fmt.Sprintf(`(?i)^(%s)`, key))
	for _, v := range datas {
		if match.MatchString(v.Key) {
			list = append(list, v.Value)
		}
	}

	return list
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:27,代碼來源:search.go

示例13: getKDMAutoLoginUser

//Default config: /usr/share/config/kdm/kdmrc
func getKDMAutoLoginUser(file string) (string, error) {
	if !dutils.IsFileExist(file) {
		return "", fmt.Errorf("Not found this file: %s", file)
	}

	v, exist := dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginEnable", true)
	if !exist {
		return "", nil
	}

	enable, ok := v.(bool)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	if !enable {
		return "", nil
	}

	v, exist = dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginUser", "")
	if !exist {
		return "", nil
	}

	var name string
	name, ok = v.(string)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	return name, nil
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:35,代碼來源:manager.go

示例14: isAppInBlackList

func isAppInBlackList() bool {
	X := getXUtil()
	if X == nil {
		return false
	}

	xid, _ := getActiveWindow(X)
	pid, _ := getWindowPid(X, xid)

	filename := fmt.Sprintf("/proc/%v/cmdline", pid)
	if !dutils.IsFileExist(filename) {
		return false
	}

	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		logger.Warningf("ReadFile '%s' failed: %v", filename, err)
		return false
	}

	blackList := zoneSettings().GetStrv("black-list")
	for _, target := range blackList {
		if strings.Contains(string(contents), target) {
			return true
		}
	}

	return false
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:29,代碼來源:window_state.go

示例15: CopyFile

func CopyFile(src, dst string, copyFlag CopyFlag) error {
	srcStat, err := os.Lstat(src)
	if err != nil {
		return err
	}

	if srcStat.IsDir() {
		return fmt.Errorf("error src is a directory: %s", src)
	}

	if utils.IsFileExist(dst) {
		dstStat, err := os.Lstat(dst)
		if err != nil {
			return fmt.Errorf("error os.Lstat dst %s: %s", dst, err)
		}

		if dstStat.IsDir() {
			dst = path.Join(dst, path.Base(src))
		} else {
			if (copyFlag & CopyFileOverWrite) == 0 {
				return fmt.Errorf("error dst %s is alreadly exist", dst)
			}
		}
	}

	return copyFileAux(src, dst, copyFlag)
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:27,代碼來源:copyfile.go


注:本文中的pkg/linuxdeepin/com/lib/utils.IsFileExist函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。