Skip to content

Commit

Permalink
添加查看历史目录的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
821869798 committed Sep 10, 2023
1 parent 5185914 commit 2eba9a8
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ excel merge diff tools,excel对比合并工具,把excel转成csv格式,然

### windows

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

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

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

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

- 可以查看历史记录,通过上述设置好之后,第二次打开会进入选择模式,可以选择查看历史记录目录

![select_mode](doc/img/select_mode.png)

## TODO

- excel合并保留更多格式数据。
15 changes: 9 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

type RawGlobalConfig struct {
DiffOutputType string `toml:"diff_output"`
MergeOutputType string `toml:"merge_output"`
CompareTools string `toml:"compare_exe"`
DiffArgs string `toml:"diff_arg"`
MergeArgs string `toml:"merge_arg"`
DiffOutputType string `toml:"diff_output"`
MergeOutputType string `toml:"merge_output"`
CompareTools string `toml:"compare_exe"`
DiffArgs string `toml:"diff_arg"`
MergeArgs string `toml:"merge_arg"`
DiffHistoryCount int `toml:"diff_history_count"`
}

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

ConfigFilePath = fanpath.AbsOrRelExecutePath(configFile)
err := os.WriteFile(ConfigFilePath, []byte(configTemplate), 0644)
Expand Down
38 changes: 36 additions & 2 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/821869798/excel_merge/convert"
"github.com/821869798/excel_merge/define"
"github.com/821869798/excel_merge/source"
"github.com/821869798/fankit/fanopen"
"github.com/821869798/fankit/fanpath"
"github.com/821869798/fankit/fanstr"
"github.com/gookit/slog"
Expand All @@ -21,14 +22,35 @@ func Run(fileList []string) {
var file1 string = fileList[0]
if define.IsExcelFile(file1) {
file1 = convertFile(file1)
defer os.Remove(file1)
}
var file2 string = fileList[1]
if define.IsExcelFile(file2) {
file2 = convertFile(file2)
defer os.Remove(file2)
}

defer func() {
// 删除超过历史上限的文件
diffTempPath := filepath.Join(os.TempDir(), define.WorkGenCSVDir)
if !fanpath.ExistPath(diffTempPath) {
return
}
fileList, err := fanpath.GetFileListByModTime(diffTempPath)
if err != nil {
slog.Errorf("[diff] Get diff history file list error: %v", err)
return
}
if len(fileList) <= config.GlobalConfig.DiffHistoryCount {
return
}
overCount := len(fileList) - config.GlobalConfig.DiffHistoryCount
for i := 0; i < overCount; i++ {
err = os.Remove(fileList[i])
if err != nil {
slog.Errorf("[diff] Remove diff history file error: %v", err)
}
}
}()

diffArg := fanstr.FormatFieldName(config.GlobalConfig.DiffArgs, "left", file1, "right", file2)
cmd := exec.Command(fanpath.AbsOrRelExecutePath(config.GlobalConfig.CompareTools), diffArg...)
output, err := cmd.CombinedOutput()
Expand Down Expand Up @@ -77,3 +99,15 @@ func convertFile(file string) string {

return outputFile
}

func ViewHistoryPath() {
diffPath := filepath.Join(os.TempDir(), define.WorkGenCSVDir)
if !fanpath.ExistPath(diffPath) {
slog.Panicf("[diff] Diff history path not exist: %s", diffPath)
return
}
err := fanopen.Start(diffPath)
if err != nil {
slog.Panicf("[diff] Open diff history path error: %v", err)
}
}
Binary file added doc/img/select_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ compare_exe = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe"
# 对比工具参数{left} {right}
diff_arg = "{left} {right}"
# 合并工具参数
merge_arg = "{remote} {local} {base} {output}"
merge_arg = "{remote} {local} {base} {output}"
# 对比历史记录数量
diff_history_count = 50
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/821869798/excel_merge
go 1.20

require (
github.com/821869798/fankit v0.0.3
github.com/821869798/fankit v0.0.5
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/BurntSushi/toml v1.3.2
github.com/gookit/slog v0.5.4
github.com/ncruces/zenity v0.10.10
github.com/xuri/excelize/v2 v2.7.1
golang.org/x/sys v0.10.0
golang.org/x/sys v0.12.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/821869798/fankit v0.0.3 h1:aN0IKOfMzbEvId9cjY+AX5WZHfWhw2zzLv1vjkJKarM=
github.com/821869798/fankit v0.0.3/go.mod h1:73w1EUt6i92eswVBeuUVVmHtjidOqcVsmwL3beokqQA=
github.com/821869798/fankit v0.0.5 h1:zzWC7LNbqI9XYoth0Liv3toPiZiEZIXL7vNQ/clMWGM=
github.com/821869798/fankit v0.0.5/go.mod h1:73w1EUt6i92eswVBeuUVVmHtjidOqcVsmwL3beokqQA=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
Expand Down Expand Up @@ -144,8 +144,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down
39 changes: 38 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/821869798/excel_merge/diff"
"github.com/821869798/excel_merge/merge"
"github.com/821869798/excel_merge/register_tools"
"github.com/821869798/fankit/admin"
"github.com/821869798/fankit/console"
"github.com/821869798/fankit/fanpath"
"github.com/AlecAivazis/survey/v2"
"github.com/gookit/slog"
"os"
)
Expand Down Expand Up @@ -62,9 +64,13 @@ func main() {
slog.Panicf("Write new config toml file failed: %v", err)
}
parseConfig()
register_tools.Run()
return
}

register_tools.Run()
// 进入选择模式
parseConfig()
selectMode()
return
}

Expand Down Expand Up @@ -102,3 +108,34 @@ func parseConfig() {
slog.Infof("Load config toml success")
}
}

func selectMode() {
var answer survey.OptionAnswer
var options = []string{
"View Difference Comparison History Catalog(查看差异对比历史目录)",
"View Merge History Catalog(查看合并历史目录)",
"Register Comparison Tool(注册对比工具)",
}
defaultIndex := 0
if admin.IsAdministrator() {
defaultIndex = 2
}
prompt := &survey.Select{
Message: `Please select a mode(请选择一个模式):`,
Options: options,
Default: defaultIndex,
}
err := survey.AskOne(prompt, &answer)
if err != nil {
slog.Panicf("[main] select mode failed error: %v", err)
return
}
switch answer.Index {
case 0:
diff.ViewHistoryPath()
case 1:
merge.ViewHistoryPath()
case 2:
register_tools.Run()
}
}
13 changes: 13 additions & 0 deletions merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/821869798/excel_merge/define"
"github.com/821869798/excel_merge/source"
"github.com/821869798/fankit/console"
"github.com/821869798/fankit/fanopen"
"github.com/821869798/fankit/fanpath"
"github.com/821869798/fankit/fanstr"
"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -261,3 +262,15 @@ func mergeToExcel(csvFilePath string, mergeExcelFiles []string, outputExcelFileP
err = baseExcelFile.SaveAs(outputExcelFilePath)
return err
}

func ViewHistoryPath() {
mergePath := fanpath.RelExecuteDir(define.WorkMergeTempDir)
if !fanpath.ExistPath(mergePath) {
slog.Panicf("[merge] Not found merge history path: %s", mergePath)
return
}
err := fanopen.Start(mergePath)
if err != nil {
slog.Panicf("[merge] Open merge history path error: %v", err)
}
}

0 comments on commit 2eba9a8

Please sign in to comment.