Skip to content

Commit

Permalink
Support netdrive reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
guenhter committed Jun 25, 2024
1 parent 3eb607b commit 45adfc6
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 107 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
path: SimpleFolderSyncer.msi

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Simple Folder Syncer

Currently workin progress. Updates to the Docs will follow...
The

## Prerequisites

Expand Down
8 changes: 6 additions & 2 deletions install-schedule.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
@echo off

set "BatchFilePath='%programfiles%\Simple Folder Syncer\simple-folder-syncer.exe'"
set "ReconnectDrivePath='%programfiles%\Simple Folder Syncer\reconnect-netdrive.bat'"

set "TaskName=Simple Folder Syncer"
set "TaskDescription=Run my batch file daily"

:: https://learn.microsoft.com/de-de/windows/win32/taskschd/schtasks
schtasks /create /f /tn "%TaskName%" /tr "%BatchFilePath%" /sc hourly
@REM https://learn.microsoft.com/de-de/windows/win32/taskschd/schtasks
schtasks /create /f /tn "%TaskName%" /tr "%BatchFilePath%" /sc hourly /mo 1

@REM This is only a workaround until the actual SSHFS drive reconnecting is implemented.
schtasks /create /f /tn "Reconnect SSHFS drive" /tr "%ReconnectDrivePath%" /sc minute /mo 30
5 changes: 3 additions & 2 deletions package.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<Feature Id="Main">
<Component Directory="SyncerFolder" Guid="ef88aca5-ca0f-49b3-a95b-385d7c9a2965">
<File Source="target\\release\\simple-folder-syncer.exe" />
<File Source="reconnect-netdrive.bat" />
<File Id="InstallScheuduleCmd" Source="install-schedule.bat" />
<File Id="UninstallScheuduleCmd" Source="uninstall-schedule.bat" />
</Component>
</Feature>

<CustomAction Id='InstallSchedule' FileRef='InstallScheuduleCmd' ExeCommand='' Execute='immediate' Impersonate='no' Return='check' />
<CustomAction Id='UninstallSchedule' FileRef='UninstallScheuduleCmd' ExeCommand='' Execute='immediate' Impersonate='no' Return='ignore' />
<CustomAction Id='InstallSchedule' FileRef='InstallScheuduleCmd' ExeCommand='' Execute='immediate' Impersonate='yes' Return='check' />
<CustomAction Id='UninstallSchedule' FileRef='UninstallScheuduleCmd' ExeCommand='' Execute='immediate' Impersonate='yes' Return='ignore' />

<InstallExecuteSequence>
<Custom Action="InstallSchedule" After="InstallFinalize" Condition="NOT Installed"/>
Expand Down
47 changes: 47 additions & 0 deletions reconnect-netdrive.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@echo off

setlocal enabledelayedexpansion

for /F "tokens=*" %%l in ('net use ^| findstr /i "\\sshfs"') do set net_use_line=%%l

for %%a in (%net_use_line%) do (
echo %%a|find "\\sshfs" >nul

if errorlevel 1 (
set previous=%%a
) else (
set drive=!previous!
)
)

IF [!drive!] == [] (
exit /B 0
)

for %%a in (%net_use_line%) do (
if "%%a"=="%drive%" (
set "nextToken=1"
) else if defined nextToken (
set "remote=%%a"
set "nextToken="
)
)

IF [!remote!] == [] (
exit /B 0
)

echo Drive: !drive!
echo Remote: !remote!


if not exist "!drive!" (
echo Reconnect drive now...
net use !drive! !remote!
) else (
echo Nothing to do. Drive is already connected.
)

endlocal

exit /B 0
Loading

0 comments on commit 45adfc6

Please sign in to comment.