Skip to content

Commit

Permalink
fix for non-synced files being deleted
Browse files Browse the repository at this point in the history
+ post-refactoring fixes
  • Loading branch information
JohnTheGr8 committed Sep 19, 2013
1 parent 8010c19 commit 1c677ee
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 62 deletions.
3 changes: 1 addition & 2 deletions FTPboxLib/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public AccountController()
SyncQueue = new SyncQueue(this);

Client = new Client(this);

}

#region Properties
Expand Down Expand Up @@ -227,7 +226,7 @@ public string GetHttpLink(string file)
/// <param name="index">item's index in list</param>
public string LinkToRecent(int index = 0)
{
return GetHttpLink(RecentList[index].CommonPath);
return index < RecentList.Count ? GetHttpLink(RecentList[index].CommonPath) : null;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions FTPboxLib/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ public bool CheckWorkingDirectory()
}
catch (Exception ex)
{
if (!isConnected) Log.Write(l.Warning, "Client not connected!");
Common.LogError(ex);
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions FTPboxLib/FileLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public FileLog(AccountController account)
{
this.controller = account;

Files = new List<FileLogItem>();
Folders = new List<string>();

Log.Write(l.Info, "Opened FileLog");
}

Expand Down
35 changes: 13 additions & 22 deletions FTPboxLib/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,12 @@ public Profile()

public string HomePath { get; set; }

public bool AskForPassword = false;

#endregion

#region Methods

/// <summary>
/// Load the profile data from the settings file
/// </summary>
public void Load()
{
Settings.AskForPassword = false;
AddAccount(Settings.DefaultProfile.Account.Host, Settings.DefaultProfile.Account.Username,
Common.Decrypt(Settings.DefaultProfile.Account.Password), Settings.DefaultProfile.Account.Port);
AddPaths(Settings.DefaultProfile.Paths.Remote, Settings.DefaultProfile.Paths.Local,
Settings.DefaultProfile.Paths.Parent);

Account.Protocol = Settings.DefaultProfile.Account.Protocol;
Account.FtpsMethod = Settings.DefaultProfile.Account.FtpsMethod;

Account.FtpSecurityProtocol = Settings.DefaultProfile.Account.FtpSecurityProtocol;

Account.SyncMethod = Settings.DefaultProfile.Account.SyncMethod;
Account.SyncFrequency = Settings.DefaultProfile.Account.SyncFrequency;
}

public void AddAccount(string host, string user, string pass, int port)
{
Account = new Account()
Expand Down Expand Up @@ -93,16 +75,25 @@ public void Clear()

#region Serialization

private string tmpPassword = string.Empty;

[OnSerializing]
internal void OnSerializing(StreamingContext context)
{
Account.Password = Common.Encrypt(Account.Password);
tmpPassword = Account.Password;
if (AskForPassword)
Account.Password = string.Empty;
else
Account.Password = Common.Encrypt(Account.Password);
}

[OnSerialized]
internal void OnSerialized(StreamingContext context)
{
Account.Password = Common.Decrypt(Account.Password);
if (AskForPassword)
Account.Password = tmpPassword;
else
Account.Password = Common.Decrypt(Account.Password);
}

[OnDeserialized]
Expand Down
6 changes: 2 additions & 4 deletions FTPboxLib/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class Settings
public static bool IsDebugMode;
public static bool IsNoMenusMode;

public static bool AskForPassword;

#endregion

#region Methods
Expand Down Expand Up @@ -82,11 +80,11 @@ public static void Load()
/// <summary>
/// Saves Profiles & General settings to the config file
/// </summary>
public static void Save()
public static void Save(AccountController account = null)
{
SaveGeneral();

SaveProfile();
SaveProfile(account);

SaveCertificates();
}
Expand Down
78 changes: 49 additions & 29 deletions FTPboxLib/SyncQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,38 +532,58 @@ private void CheckUpdateItem(SyncQueueItem item)
}

// Look for local files that should be deleted
foreach (var local in new DirectoryInfo(item.LocalPath).GetFiles("*", SearchOption.AllDirectories).Where(x => controller.ItemGetsSynced(controller.GetCommonPath(x.FullName, true))))
if (AllItems.All(x => controller.GetCommonPath(x.FullPath, false) != controller.GetCommonPath(local.FullName, true)))
Add(new SyncQueueItem(controller)
foreach (var local in new DirectoryInfo(item.LocalPath).GetFiles("*", SearchOption.AllDirectories))
{
var cpath = controller.GetCommonPath(local.FullName, true);
// continue if the file is ignored
if (!controller.ItemGetsSynced(cpath)) continue;
// continue if the file was found in the remote list
if (AllItems.Any(x => controller.GetCommonPath(x.FullPath, false) == cpath)) continue;
// continue if the file is not in the log, or is changed compared to the logged data TODO: Maybe send to remote folder?
if (controller.FileLog.Files.All(x => x.CommonPath != cpath) ||
controller.FileLog.Files.Find(x => x.CommonPath == cpath).Local != local.LastWriteTime) continue;

// Seems like the file was deleted from the remote folder
Add(new SyncQueueItem(controller)
{
Item = new ClientItem
{
Item = new ClientItem
{
FullPath = controller.GetCommonPath(local.FullName, true),
Name = local.Name,
Type = ClientItemType.File,
LastWriteTime = local.LastWriteTime,
Size = local.Length
},
ActionType = ChangeAction.deleted,
SyncTo = SyncTo.Local
});
FullPath = cpath,
Name = local.Name,
Type = ClientItemType.File,
LastWriteTime = local.LastWriteTime,
Size = local.Length
},
ActionType = ChangeAction.deleted,
SyncTo = SyncTo.Local
});
}
// Look for local folders that should be deleted
foreach (var local in new DirectoryInfo(item.LocalPath).GetDirectories("*", SearchOption.AllDirectories).Where(x => controller.ItemGetsSynced(controller.GetCommonPath(x.FullName, true))))
if (AllItems.All(x => controller.GetCommonPath(x.FullPath, false) != controller.GetCommonPath(local.FullName, true)))
Add(new SyncQueueItem(controller)
{
Item = new ClientItem
{
FullPath = controller.GetCommonPath(local.FullName, true),
Name = local.Name,
Type = ClientItemType.Folder,
LastWriteTime = DateTime.MinValue, // Doesn't matter
Size = 0x0 // Doesn't matter
},
ActionType = ChangeAction.deleted,
SyncTo = SyncTo.Local
});
foreach (var local in new DirectoryInfo(item.LocalPath).GetDirectories("*", SearchOption.AllDirectories))
{
var cpath = controller.GetCommonPath(local.FullName, true);
// continue if the folder is ignored
if (!controller.ItemGetsSynced(cpath)) continue;
// continue if the folder was found in the remote list
if (AllItems.Any(x => controller.GetCommonPath(x.FullPath, false) == cpath)) continue;
// continue if the folder is not in the log TODO: Maybe send to remote folder?
if (controller.FileLog.Folders.All(x => x != cpath)) continue;

// Seems like the folder was deleted from the remote folder
Add(new SyncQueueItem(controller)
{
Item = new ClientItem
{
FullPath = controller.GetCommonPath(local.FullName, true),
Name = local.Name,
Type = ClientItemType.Folder,
LastWriteTime = DateTime.MinValue, // Doesn't matter
Size = 0x0 // Doesn't matter
},
ActionType = ChangeAction.deleted,
SyncTo = SyncTo.Local
});
}
RemoveLast(StatusType.Success);
}

Expand Down
Binary file modified Windows/FTPbox.v11.suo
Binary file not shown.
Binary file removed Windows/FTPbox/FTPboxLib.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Windows/FTPbox/Forms/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void bDone_Click(object sender, EventArgs e)
Program.Account.Client.Connect();
Log.Write(l.Debug, "Connected: {0}", Program.Account.Client.isConnected);

Settings.AskForPassword = cAskForPass.Checked;
Program.Account.AskForPassword = cAskForPass.Checked;

Hide();
}
Expand Down
2 changes: 1 addition & 1 deletion Windows/FTPbox/Forms/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void bDone_Click(object sender, EventArgs e)

Program.Account.AddPaths(tFullDir.Text, tPath.Text, tParent.Text);

Settings.Save();
Settings.Save(Program.Account);

Program.Account.Client.WorkingDirectory = Program.Account.Paths.Remote;

Expand Down
6 changes: 3 additions & 3 deletions Windows/FTPbox/Forms/fMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,11 @@ private void SyncArgItems(string[] args)
MessageBox.Show("You cannot use this for files that are not inside the FTPbox folder.", "FTPbox - Invalid file", MessageBoxButtons.OK, MessageBoxIcon.Error);
continue;
}
var cpath = Program.Account.GetCommonPath(s, true);
bool exists = Program.Account.Client.Exists(cpath);

if (Common.PathIsFile(s) && File.Exists(s))
{
var cpath = Program.Account.GetCommonPath(s, true);
bool exists = Program.Account.Client.Exists(cpath);
Program.Account.SyncQueue.Add(new SyncQueueItem (Program.Account)
{
Item = new ClientItem
Expand Down Expand Up @@ -1079,7 +1079,7 @@ private void SyncArgItems(string[] args)
LastWriteTime = DateTime.MinValue
},
ActionType = ChangeAction.changed,
SyncTo = SyncTo.Local,
SyncTo = exists ? SyncTo.Local : SyncTo.Remote,
SkipNotification = true
});
}
Expand Down

0 comments on commit 1c677ee

Please sign in to comment.