Files
duplicati/Duplicati/GUI/DynamicSetupHelper.cs
T
kenneth.skovhede@gmail.com b81d63ea73 Fixed a bug with async uploads that caused some files to no be uploaded.
Fixed a protential race condition with warning messages and file counts (cosmetic only) when using async transfers.
Spelling correction, Seperator -> Separator.
Changed so a restore operation can also supply advanced options.
Changed the format of timestamps in filenames to follow the Duplicity convention, which removes the need for --time-separator and --use-short-filenames.
Moved the URL utility into Core, to avoid compilation errors with Monodevelop.
Reorganized the runner to better support the LiveControls on all operations rather than only for backup/restore.

Update issue #210
Status: Fixed
I have now changed the time format to follow the Duplicity naming convention.
This means that all filenames are now generated with the time set as "yyyyMMddTHHmmssZ".
This format is more portable across all platforms, and easily sortable/readable.
The drawback is that the Z indicates UTC time, so if one looks at the filenames, 
the times are not local. The motivation for this is to avoid trouble
with daylight savings time offsets.

There is full backwards compatibility as long as backups have not used more than
one character for --time-separator (only possible via commandline).
This new format means that the options --time-separator and --use-short-filenames
are now deprecated and removed from the user interface. It is possible to
access them from the advanced options page, along with the --use-old-filenames option.

If anyone needs these options for some reason, let me know, otherwise they will be removed
in a later version.



git-svn-id: https://duplicati.googlecode.com/svn/trunk@523 59da171f-624f-0410-aa54-27559c288bec
2010-09-25 12:02:14 +00:00

168 lines
8.4 KiB
C#

#region Disclaimer / License
// Copyright (C) 2010, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Datamodel;
namespace Duplicati.GUI
{
/// <summary>
/// This class generates a list of source folders and matching filters, based on the users choices
/// </summary>
public static class DynamicSetupHelper
{
/// <summary>
/// Gets a source folder setup, based on the users filter selection
/// </summary>
/// <param name="wrapper">The wrapper instance with the user selection</param>
/// <param name="filters">The filter settings</param>
/// <returns>The source folder string</returns>
public static string[] GetSourceFolders(Wizard_pages.WizardSettingsWrapper wrapper, ApplicationSettings settings, List<KeyValuePair<bool, string>> filters)
{
if (wrapper.SelectFilesUI.Version >= 2 && wrapper.SelectFilesUI.UseSimpleMode)
{
return GetSourceFolders(
wrapper.SelectFilesUI.IncludeDocuments,
wrapper.SelectFilesUI.IncludeMusic,
wrapper.SelectFilesUI.IncludeImages,
wrapper.SelectFilesUI.IncludeDesktop,
wrapper.SelectFilesUI.IncludeSettings,
settings,
filters);
}
else
{
return PrependFilterList(wrapper.SourcePath.Split(System.IO.Path.PathSeparator), settings, filters);
}
}
/// <summary>
/// Gets a source folder setup, based on the users filter selection
/// </summary>
/// <param name="task">The Task instance with the user setup</param>
/// <param name="filters">The filter settings</param>
/// <returns>The source folder string</returns>
public static string[] GetSourceFolders(Task task, ApplicationSettings settings, List<KeyValuePair<bool, string>> filters)
{
if (task.Extensions.SelectFiles_Version >= 2 && task.Extensions.SelectFiles_UseSimpleMode)
{
return GetSourceFolders(
task.Extensions.SelectFiles_IncludeDocuments,
task.Extensions.SelectFiles_IncludeMusic,
task.Extensions.SelectFiles_IncludeImages,
task.Extensions.SelectFiles_IncludeDesktop,
task.Extensions.SelectFiles_IncludeAppData,
settings,
filters);
}
else
{
return PrependFilterList(task.SourcePath.Split(System.IO.Path.PathSeparator), settings, filters);
}
}
/// <summary>
/// Prepends extra filters to exclude the temp folder and the Duplicati signature cache
/// </summary>
/// <param name="sourceFolders">The list of folders being backed up</param>
/// <param name="filters">The current set of filters to prepend to</param>
/// <returns>The sourceFolders</returns>
private static string[] PrependFilterList(string[] sourceFolders, ApplicationSettings settings, List<KeyValuePair<bool, string>> filters)
{
string[] exFolders = new string[] {
Library.Core.Utility.AppendDirSeparator(System.Environment.ExpandEnvironmentVariables(settings.SignatureCachePath)),
Library.Core.Utility.AppendDirSeparator(System.Environment.ExpandEnvironmentVariables(settings.TempPath))
};
foreach (string i in sourceFolders)
foreach (string x in exFolders)
if (x.StartsWith(i, Library.Core.Utility.ClientFilenameStringComparision))
filters.Insert(0, new KeyValuePair<bool, string>(false, Library.Core.FilenameFilter.ConvertGlobbingToRegExp(x)));
return sourceFolders;
}
/// <summary>
/// Gets a source folder setup, based on the users folder selection
/// </summary>
/// <param name="filters">The filter settings</param>
/// <param name="includeDocuments">True if documents should be included</param>
/// <param name="includeMusic">True if music should be included</param>
/// <param name="includeImages">True if images should be included</param>
/// <param name="includeDesktop">True if desktop files should be included</param>
/// <param name="includeSettings">True if settings should be included</param>
/// <returns>The source folder string</returns>
private static string[] GetSourceFolders(bool includeDocuments, bool includeMusic, bool includeImages, bool includeDesktop, bool includeSettings, ApplicationSettings settings, List<KeyValuePair<bool, string>> filters)
{
string myPictures = Library.Core.Utility.AppendDirSeparator(System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
string myMusic = Library.Core.Utility.AppendDirSeparator(System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic));
string desktop = Library.Core.Utility.AppendDirSeparator(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
string appData = Library.Core.Utility.AppendDirSeparator(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
string myDocuments = Library.Core.Utility.AppendDirSeparator(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
List<string> folders = new List<string>();
List<string> exfolders = new List<string>();
(includeDocuments ? folders : exfolders).Add(myDocuments);
(includeImages ? folders : exfolders).Add(myPictures);
(includeMusic ? folders : exfolders).Add(myMusic);
(includeDesktop ? folders : exfolders).Add(desktop);
(includeSettings ? folders : exfolders).Add(appData);
if (folders.Count == 0)
throw new Exception(Strings.DynamicSetupHelper.NoFoldersInSetupError);
//Figure out if any folders are subfolders, and only include the parents
for (int i = 0; i < folders.Count; i++)
for (int j = i + 1; j < folders.Count; j++)
if (folders[i].StartsWith(folders[j], Library.Core.Utility.ClientFilenameStringComparision))
{
folders.RemoveAt(i);
i--;
break; //Break inner, continue outer
}
else if (folders[j].StartsWith(folders[i], Library.Core.Utility.ClientFilenameStringComparision))
{
folders.RemoveAt(j);
i = -1; //Restart loop
break; //Break inner, continue outer
}
//Add filters to exclude de-selected folders
foreach (string s in exfolders)
{
foreach (string s2 in folders)
if (s.StartsWith(s2))
{
filters.Insert(0, new KeyValuePair<bool, string>(false, Library.Core.FilenameFilter.ConvertGlobbingToRegExp(s)));
break;
}
}
string fi = "";
foreach (KeyValuePair<bool, string> x in filters)
fi += x.Value + ";";
return PrependFilterList(folders.ToArray(), settings, filters);
}
}
}