-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3616192
commit feafeb1
Showing
6 changed files
with
239 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ fox.wiki/* | |
fox.exe | ||
|
||
fox.wiki | ||
|
||
go.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
// Copyright 2014 The StudyGolang Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// http://studygolang.com | ||
// Author: polaris [email protected] | ||
|
||
package util | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
"github.com/zouhuigang/package/zfileutil" | ||
) | ||
|
||
// 检查文件或目录是否存在 | ||
|
@@ -67,3 +64,68 @@ func GetCurrentDirectory() string { | |
} | ||
return strings.Replace(dir, "\\", "/", -1) //将\替换成/ | ||
} | ||
|
||
func Walkdir(path string) (error, []zfileutil.FileList) { | ||
var wg sync.WaitGroup | ||
|
||
//读取文件 | ||
var filelist []zfileutil.FileList | ||
c := make(chan []zfileutil.FileList) | ||
is_success := make(chan bool) | ||
|
||
dir, err := ioutil.ReadDir(path) | ||
if err != nil { | ||
return err, nil | ||
} | ||
for _, fi := range dir { | ||
fpath := filepath.FromSlash(path + "/" + fi.Name()) | ||
|
||
if fi.IsDir() { | ||
if strings.HasPrefix(fi.Name(), ".") { | ||
continue | ||
} | ||
if strings.HasPrefix(fi.Name(), "..") { | ||
continue | ||
} | ||
if strings.Contains(fi.Name(), "lost+found") { | ||
continue | ||
} | ||
|
||
if strings.Contains(fi.Name(), "fox.theme") { | ||
continue | ||
} | ||
wg.Add(1) | ||
go scanDir(&wg, fpath, c) | ||
} else { | ||
cur_file := zfileutil.GetFormatFileInfo(fpath, fi) | ||
filelist = append(filelist, cur_file) | ||
} | ||
} | ||
|
||
//一直阻塞直到chan c关闭 | ||
go func() { | ||
for { | ||
select { | ||
case result := <-c: | ||
filelist = append(filelist, result...) | ||
case <-is_success: | ||
return | ||
} | ||
} | ||
}() | ||
|
||
wg.Wait() | ||
|
||
is_success <- true | ||
return nil, filelist | ||
|
||
} | ||
|
||
func scanDir(wg *sync.WaitGroup, rootPath string, c chan []zfileutil.FileList) { | ||
defer wg.Done() | ||
filelist := make([]zfileutil.FileList, 0) | ||
if f, _ := zfileutil.ScanFiles(rootPath); len(f) > 0 { | ||
filelist = append(filelist, f...) | ||
} | ||
c <- filelist | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/speps/go-hashids" | ||
) | ||
|
||
//salt 盐值 | ||
const salt = "fox_" | ||
|
||
//Encode 混淆 | ||
func Encode(data int) string { | ||
hd := hashids.NewData() | ||
hd.Salt = salt | ||
h, _ := hashids.NewWithData(hd) | ||
e, _ := h.Encode([]int{data}) | ||
return e | ||
} | ||
|
||
//Decode 还原混淆 | ||
func Decode(data string) int { | ||
hd := hashids.NewData() | ||
hd.Salt = salt | ||
h, _ := hashids.NewWithData(hd) | ||
e, _ := h.DecodeWithError(data) | ||
return e[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Windows Registry Editor Version 5.00 | ||
|
||
[HKEY_CLASSES_ROOT\*\shell\fox] | ||
@="Open with Fox" | ||
"Icon"="D:\\workspacego\\src\\fox\\fox.exe" | ||
|
||
[HKEY_CLASSES_ROOT\*\shell\fox\command] | ||
@="\"D:\\workspacego\\src\\fox\\fox.exe\" \"%1\"" | ||
|
||
Windows Registry Editor Version 5.00 | ||
|
||
[HKEY_CLASSES_ROOT\Directory\shell\fox] | ||
@="Open with Fox" | ||
"Icon"="D:\\workspacego\\src\\fox\\fox.exe" | ||
|
||
[HKEY_CLASSES_ROOT\Directory\shell\fox\command] | ||
@="\"D:\\workspacego\\src\\fox\\fox.exe\" \"%V\"" | ||
|
||
Windows Registry Editor Version 5.00 | ||
|
||
[HKEY_CLASSES_ROOT\Directory\Background\shell\fox] | ||
@="Open with Fox" | ||
"Icon"="D:\\workspacego\\src\\fox\\fox.exe" | ||
|
||
[HKEY_CLASSES_ROOT\Directory\Background\shell\fox\command] | ||
@="\"D:\\workspacego\\src\\fox\\fox.exe\" \"%V\"" |