Skip to content
Snippets Groups Projects
Commit 59118d42 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Auto-create user directories in incoming.

If a directory in C:\Users\ has a matching one in the target location,
make sure the corresponding one exists in the incoming directory.

Fixes #10.
parent 0fcb9ab4
No related branches found
No related tags found
No related merge requests found
...@@ -21,10 +21,16 @@ namespace AutoTx ...@@ -21,10 +21,16 @@ namespace AutoTx
private string _statusPath; private string _statusPath;
private string _incomingPath; private string _incomingPath;
private string _managedPath; private string _managedPath;
private string[] _remoteUserDirs;
private string[] _localUserDirs;
private List<string> _transferredFiles = new List<string>(); private List<string> _transferredFiles = new List<string>();
private int _txProgress; private int _txProgress;
private DateTime _lastUserDirCheck = DateTime.Now;
// the transfer state: // the transfer state:
private enum TxState private enum TxState
{ {
...@@ -60,6 +66,7 @@ namespace AutoTx ...@@ -60,6 +66,7 @@ namespace AutoTx
InitializeComponent(); InitializeComponent();
CreateEventLog(); CreateEventLog();
LoadSettings(); LoadSettings();
CreateIncomingDirectories();
} }
/// <summary> /// <summary>
...@@ -410,6 +417,10 @@ namespace AutoTx ...@@ -410,6 +417,10 @@ namespace AutoTx
CheckFreeDiskSpace(); CheckFreeDiskSpace();
UpdateServiceState(); UpdateServiceState();
var delta = DateTime.Now - _lastUserDirCheck;
if (delta.Seconds >= 10)
CreateIncomingDirectories();
// tasks depending on the service state: // tasks depending on the service state:
if (_serviceSuspended) { if (_serviceSuspended) {
// make sure to pause any running transfer: // make sure to pause any running transfer:
...@@ -852,6 +863,35 @@ namespace AutoTx ...@@ -852,6 +863,35 @@ namespace AutoTx
return retval; return retval;
} }
/// <summary>
/// Helper to create directories for all users that have one in the local
/// user directory (C:\Users) AND in the DestinationDirectory.
/// </summary>
private void CreateIncomingDirectories() {
_localUserDirs = new DirectoryInfo(@"C:\Users")
.GetDirectories()
.Select(d => d.Name)
.ToArray();
_remoteUserDirs = new DirectoryInfo(_config.DestinationDirectory)
.GetDirectories()
.Select(d => d.Name)
.ToArray();
foreach (var userDir in _localUserDirs) {
// don't create an incoming directory for the same name as the
// temporary transfer location:
if (_config.TmpTransferDir == userDir)
continue;
// don't create a directory if it doesn't exist on the target:
if (!_remoteUserDirs.Contains(userDir))
continue;
CreateNewDirectory(Path.Combine(_incomingPath, userDir), false);
}
_lastUserDirCheck = DateTime.Now;
}
#endregion #endregion
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment