Skip to content

Commit

Permalink
Add option to not extract received directories
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
Jacalz committed Jan 15, 2024
1 parent 7370c87 commit c27def8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion internal/transport/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (c *Client) NewReceive(code string) (*wormhole.IncomingMessage, error) {
func (c *Client) SaveToDisk(msg *wormhole.IncomingMessage, targetPath string, progress func(int64, int64)) (err error) {
contents := util.NewProgressReader(msg, progress, msg.TransferBytes)

if msg.Type == wormhole.TransferDirectory && c.NoExtractDirectory {
targetPath += ".zip" // We are saving the zip-file and not extracting.
}

if !c.OverwriteExisting {
if _, err := os.Stat(targetPath); err == nil || os.IsExist(err) {
targetPath, err = addFileIncrement(targetPath)
Expand All @@ -51,7 +55,7 @@ func (c *Client) SaveToDisk(msg *wormhole.IncomingMessage, targetPath string, pr
}
}

if msg.Type == wormhole.TransferFile {
if msg.Type == wormhole.TransferFile || c.NoExtractDirectory {
var file *os.File
file, err = os.Create(targetPath) // #nosec Path is cleaned by filepath.Join().
if err != nil {
Expand Down
15 changes: 9 additions & 6 deletions internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ type Client struct {
// App is a reference to the currently running Fyne application.
App fyne.App

// CustomCode defines if we should pass a custom code or let wormhole-william generate on for us.
CustomCode bool

// DownloadPath holds the download path used for saving received files.
DownloadPath string

// NoExtractDirectory specifies if we should extract directories or not.
NoExtractDirectory bool

// Notification holds the settings value for if we have notifications enabled or not.
Notifications bool

// OverwriteExisting holds the settings value for if we should overwrite already existing files.
OverwriteExisting bool

// DownloadPath holds the download path used for saving received files.
DownloadPath string

// Defines if we should pass a custom code or let wormhole-william generate on for us.
CustomCode bool
}

// ShowNotification sends a notification if c.Notifications is true.
Expand Down
12 changes: 12 additions & 0 deletions internal/ui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type settings struct {
downloadPathEntry *widget.Entry
overwriteFiles *widget.RadioGroup
notificationRadio *widget.RadioGroup
extractRadio *widget.RadioGroup
checkUpdatesRadio *widget.RadioGroup

componentSlider *widget.Slider
Expand Down Expand Up @@ -109,6 +110,11 @@ func (s *settings) onNotificationsChanged(selected string) {
s.preferences.SetBool("Notifications", s.client.Notifications)
}

func (s *settings) onExtractChanged(selected string) {
s.client.NoExtractDirectory = selected == "Off" // UI representation is flipped.
s.preferences.SetBool("NoExtractDirectory", s.client.NoExtractDirectory)
}

func (s *settings) onCheckUpdatesChanged(selected string) {
s.preferences.SetBool("CheckUpdates", selected == "On")
}
Expand Down Expand Up @@ -171,6 +177,9 @@ func (s *settings) getPreferences(app fyne.App) {
s.client.Notifications = s.preferences.BoolWithFallback("Notifications", true)
s.notificationRadio.Selected = onOrOff(s.client.Notifications)

s.client.NoExtractDirectory = s.preferences.Bool("NoExtractDirectory")
s.extractRadio.Selected = onOrOff(!s.client.NoExtractDirectory)

checkUpdates := s.preferences.BoolWithFallback("CheckUpdates", true)
if !updater.Enabled {
checkUpdates = false
Expand Down Expand Up @@ -211,6 +220,8 @@ func (s *settings) buildUI(app fyne.App) *container.Scroll {

s.notificationRadio = &widget.RadioGroup{Options: onOffOptions, Horizontal: true, Required: true, OnChanged: s.onNotificationsChanged}

s.extractRadio = &widget.RadioGroup{Options: onOffOptions, Horizontal: true, Required: true, OnChanged: s.onExtractChanged}

s.checkUpdatesRadio = &widget.RadioGroup{Options: onOffOptions, Horizontal: true, Required: true, OnChanged: s.onCheckUpdatesChanged}

s.verifyRadio = &widget.RadioGroup{Options: onOffOptions, Horizontal: true, Required: true, OnChanged: s.onVerifyChanged}
Expand Down Expand Up @@ -240,6 +251,7 @@ func (s *settings) buildUI(app fyne.App) *container.Scroll {
newBoldLabel("Save files to"), s.downloadPathEntry,
newBoldLabel("Overwrite files"), s.overwriteFiles,
newBoldLabel("Notifications"), s.notificationRadio,
newBoldLabel("Extract received directory"), s.extractRadio,
newBoldLabel("Check for updates"), s.checkUpdatesRadio,
)

Expand Down

0 comments on commit c27def8

Please sign in to comment.