Skip to content

Commit 2eba9a8

Browse files
committed
添加查看历史目录的功能
1 parent 5185914 commit 2eba9a8

File tree

9 files changed

+110
-17
lines changed

9 files changed

+110
-17
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ excel merge diff tools,excel对比合并工具,把excel转成csv格式,然
1212

1313
### windows
1414

15-
双击打开执行文件,允许权限(用于读取和修改注册表)
15+
双击打开执行文件,允许权限(用于读取和修改注册表,只需要一次
1616

1717
1. 选择基础的对比工具之后回车确定,如果有安装`Beyond Comapre`或者使用绿色版注册了右键菜单都会识别出来
1818

@@ -33,6 +33,10 @@ excel merge diff tools,excel对比合并工具,把excel转成csv格式,然
3333

3434
- 合并基本同理,默认使用txt模式,就是正常的文本合并,合并完选择基础的excel文件,然后写回excel文件中
3535

36+
- 可以查看历史记录,通过上述设置好之后,第二次打开会进入选择模式,可以选择查看历史记录目录
37+
38+
![select_mode](doc/img/select_mode.png)
39+
3640
## TODO
3741

3842
- excel合并保留更多格式数据。

config/config.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
)
1212

1313
type RawGlobalConfig struct {
14-
DiffOutputType string `toml:"diff_output"`
15-
MergeOutputType string `toml:"merge_output"`
16-
CompareTools string `toml:"compare_exe"`
17-
DiffArgs string `toml:"diff_arg"`
18-
MergeArgs string `toml:"merge_arg"`
14+
DiffOutputType string `toml:"diff_output"`
15+
MergeOutputType string `toml:"merge_output"`
16+
CompareTools string `toml:"compare_exe"`
17+
DiffArgs string `toml:"diff_arg"`
18+
MergeArgs string `toml:"merge_arg"`
19+
DiffHistoryCount int `toml:"diff_history_count"`
1920
}
2021

2122
var (
@@ -42,7 +43,9 @@ compare_exe = "you compare tool execute path"
4243
# 对比工具参数{left} {right}
4344
diff_arg = "{left} {right}"
4445
# 合并工具参数
45-
merge_arg = "{remote} {local} {base} {output}"`
46+
merge_arg = "{remote} {local} {base} {output}"
47+
# 对比历史记录数量
48+
diff_history_count = 50`
4649

4750
ConfigFilePath = fanpath.AbsOrRelExecutePath(configFile)
4851
err := os.WriteFile(ConfigFilePath, []byte(configTemplate), 0644)

diff/diff.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/821869798/excel_merge/convert"
77
"github.com/821869798/excel_merge/define"
88
"github.com/821869798/excel_merge/source"
9+
"github.com/821869798/fankit/fanopen"
910
"github.com/821869798/fankit/fanpath"
1011
"github.com/821869798/fankit/fanstr"
1112
"github.com/gookit/slog"
@@ -21,14 +22,35 @@ func Run(fileList []string) {
2122
var file1 string = fileList[0]
2223
if define.IsExcelFile(file1) {
2324
file1 = convertFile(file1)
24-
defer os.Remove(file1)
2525
}
2626
var file2 string = fileList[1]
2727
if define.IsExcelFile(file2) {
2828
file2 = convertFile(file2)
29-
defer os.Remove(file2)
3029
}
3130

31+
defer func() {
32+
// 删除超过历史上限的文件
33+
diffTempPath := filepath.Join(os.TempDir(), define.WorkGenCSVDir)
34+
if !fanpath.ExistPath(diffTempPath) {
35+
return
36+
}
37+
fileList, err := fanpath.GetFileListByModTime(diffTempPath)
38+
if err != nil {
39+
slog.Errorf("[diff] Get diff history file list error: %v", err)
40+
return
41+
}
42+
if len(fileList) <= config.GlobalConfig.DiffHistoryCount {
43+
return
44+
}
45+
overCount := len(fileList) - config.GlobalConfig.DiffHistoryCount
46+
for i := 0; i < overCount; i++ {
47+
err = os.Remove(fileList[i])
48+
if err != nil {
49+
slog.Errorf("[diff] Remove diff history file error: %v", err)
50+
}
51+
}
52+
}()
53+
3254
diffArg := fanstr.FormatFieldName(config.GlobalConfig.DiffArgs, "left", file1, "right", file2)
3355
cmd := exec.Command(fanpath.AbsOrRelExecutePath(config.GlobalConfig.CompareTools), diffArg...)
3456
output, err := cmd.CombinedOutput()
@@ -77,3 +99,15 @@ func convertFile(file string) string {
7799

78100
return outputFile
79101
}
102+
103+
func ViewHistoryPath() {
104+
diffPath := filepath.Join(os.TempDir(), define.WorkGenCSVDir)
105+
if !fanpath.ExistPath(diffPath) {
106+
slog.Panicf("[diff] Diff history path not exist: %s", diffPath)
107+
return
108+
}
109+
err := fanopen.Start(diffPath)
110+
if err != nil {
111+
slog.Panicf("[diff] Open diff history path error: %v", err)
112+
}
113+
}

doc/img/select_mode.png

37.7 KB
Loading

examples/config.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ compare_exe = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe"
77
# 对比工具参数{left} {right}
88
diff_arg = "{left} {right}"
99
# 合并工具参数
10-
merge_arg = "{remote} {local} {base} {output}"
10+
merge_arg = "{remote} {local} {base} {output}"
11+
# 对比历史记录数量
12+
diff_history_count = 50

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/821869798/excel_merge
33
go 1.20
44

55
require (
6-
github.com/821869798/fankit v0.0.3
6+
github.com/821869798/fankit v0.0.5
77
github.com/AlecAivazis/survey/v2 v2.3.7
88
github.com/BurntSushi/toml v1.3.2
99
github.com/gookit/slog v0.5.4
1010
github.com/ncruces/zenity v0.10.10
1111
github.com/xuri/excelize/v2 v2.7.1
12-
golang.org/x/sys v0.10.0
12+
golang.org/x/sys v0.12.0
1313
)
1414

1515
require (

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/821869798/fankit v0.0.3 h1:aN0IKOfMzbEvId9cjY+AX5WZHfWhw2zzLv1vjkJKarM=
2-
github.com/821869798/fankit v0.0.3/go.mod h1:73w1EUt6i92eswVBeuUVVmHtjidOqcVsmwL3beokqQA=
1+
github.com/821869798/fankit v0.0.5 h1:zzWC7LNbqI9XYoth0Liv3toPiZiEZIXL7vNQ/clMWGM=
2+
github.com/821869798/fankit v0.0.5/go.mod h1:73w1EUt6i92eswVBeuUVVmHtjidOqcVsmwL3beokqQA=
33
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
44
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
55
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
@@ -144,8 +144,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
144144
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
145145
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
146146
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
147-
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
148-
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
147+
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
148+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
149149
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
150150
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
151151
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=

main.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"github.com/821869798/excel_merge/diff"
88
"github.com/821869798/excel_merge/merge"
99
"github.com/821869798/excel_merge/register_tools"
10+
"github.com/821869798/fankit/admin"
1011
"github.com/821869798/fankit/console"
1112
"github.com/821869798/fankit/fanpath"
13+
"github.com/AlecAivazis/survey/v2"
1214
"github.com/gookit/slog"
1315
"os"
1416
)
@@ -62,9 +64,13 @@ func main() {
6264
slog.Panicf("Write new config toml file failed: %v", err)
6365
}
6466
parseConfig()
67+
register_tools.Run()
68+
return
6569
}
6670

67-
register_tools.Run()
71+
// 进入选择模式
72+
parseConfig()
73+
selectMode()
6874
return
6975
}
7076

@@ -102,3 +108,34 @@ func parseConfig() {
102108
slog.Infof("Load config toml success")
103109
}
104110
}
111+
112+
func selectMode() {
113+
var answer survey.OptionAnswer
114+
var options = []string{
115+
"View Difference Comparison History Catalog(查看差异对比历史目录)",
116+
"View Merge History Catalog(查看合并历史目录)",
117+
"Register Comparison Tool(注册对比工具)",
118+
}
119+
defaultIndex := 0
120+
if admin.IsAdministrator() {
121+
defaultIndex = 2
122+
}
123+
prompt := &survey.Select{
124+
Message: `Please select a mode(请选择一个模式):`,
125+
Options: options,
126+
Default: defaultIndex,
127+
}
128+
err := survey.AskOne(prompt, &answer)
129+
if err != nil {
130+
slog.Panicf("[main] select mode failed error: %v", err)
131+
return
132+
}
133+
switch answer.Index {
134+
case 0:
135+
diff.ViewHistoryPath()
136+
case 1:
137+
merge.ViewHistoryPath()
138+
case 2:
139+
register_tools.Run()
140+
}
141+
}

merge/merge.go

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/821869798/excel_merge/define"
99
"github.com/821869798/excel_merge/source"
1010
"github.com/821869798/fankit/console"
11+
"github.com/821869798/fankit/fanopen"
1112
"github.com/821869798/fankit/fanpath"
1213
"github.com/821869798/fankit/fanstr"
1314
"github.com/AlecAivazis/survey/v2"
@@ -261,3 +262,15 @@ func mergeToExcel(csvFilePath string, mergeExcelFiles []string, outputExcelFileP
261262
err = baseExcelFile.SaveAs(outputExcelFilePath)
262263
return err
263264
}
265+
266+
func ViewHistoryPath() {
267+
mergePath := fanpath.RelExecuteDir(define.WorkMergeTempDir)
268+
if !fanpath.ExistPath(mergePath) {
269+
slog.Panicf("[merge] Not found merge history path: %s", mergePath)
270+
return
271+
}
272+
err := fanopen.Start(mergePath)
273+
if err != nil {
274+
slog.Panicf("[merge] Open merge history path error: %v", err)
275+
}
276+
}

0 commit comments

Comments
 (0)