From 62475719a5415de8bbcd8cd1b2e6205641a30c5b Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Sun, 5 Jul 2020 22:30:47 +0300 Subject: [PATCH] Replace MappedFiles separators if defined --- bt2qbt.go | 1 - libtorrent/torrent.go | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bt2qbt.go b/bt2qbt.go index d39456b..4b3aef0 100644 --- a/bt2qbt.go +++ b/bt2qbt.go @@ -278,7 +278,6 @@ func main() { flags.QBitDir = usr.HomeDir + sep + "Library" + sep + "Application Support" + sep + "QBittorrent" + sep + "BT_backup" + sep } - _, err := goflags.Parse(&flags) if _, err := goflags.Parse(&flags); err != nil { // https://godoc.org/github.com/jessevdk/go-flags#ErrorType if flagsErr, ok := err.(*goflags.Error); ok && flagsErr.Type == goflags.ErrHelp { os.Exit(0) diff --git a/libtorrent/torrent.go b/libtorrent/torrent.go index 74f3374..d8bb068 100644 --- a/libtorrent/torrent.go +++ b/libtorrent/torrent.go @@ -273,15 +273,22 @@ func (newstructure *NewTorrentStructure) FillSavePaths() { for _, pattern := range newstructure.Replace { newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, pattern.From, pattern.To) } + var oldsep string switch newstructure.Separator { case "\\": - newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, "/", newstructure.Separator) + oldsep = "/" case "/": - newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, "\\", newstructure.Separator) - + oldsep = "\\" } - + newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, oldsep, newstructure.Separator) newstructure.SavePath = strings.ReplaceAll(newstructure.QbtSavePath, "\\", "/") + + for num, entry := range newstructure.MappedFiles { + newentry := strings.ReplaceAll(entry, oldsep, newstructure.Separator) + if entry != newentry { + newstructure.MappedFiles[num] = newentry + } + } } func fmtime(path string) (mtime int64) {