internal static Dictionary <string, string> GetSourceNames(Serialization.Interface.IBackup backup)
        {
            var systemIO = Duplicati.Library.Snapshots.SnapshotUtility.SystemIO;

            if (backup.Sources == null || backup.Sources.Length == 0)
            {
                return(new Dictionary <string, string>());
            }

            var sources = backup.Sources.Distinct().Select(x =>
            {
                var sp = SpecialFolders.TranslateToDisplayString(x);
                if (sp != null)
                {
                    return(new KeyValuePair <string, string>(x, sp));
                }

                x = SpecialFolders.ExpandEnvironmentVariables(x);
                try
                {
                    var nx = x;
                    if (nx.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                    {
                        nx = nx.Substring(0, nx.Length - 1);
                    }
                    var n = systemIO.PathGetFileName(nx);
                    if (!string.IsNullOrWhiteSpace(n))
                    {
                        return(new KeyValuePair <string, string>(x, n));
                    }
                }
                catch
                {
                }

                if (x.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && x.Length > 1)
                {
                    return(new KeyValuePair <string, string>(x, x.Substring(0, x.Length - 1).Substring(x.Substring(0, x.Length - 1).LastIndexOf("/", StringComparison.Ordinal) + 1)));
                }
                else
                {
                    return(new KeyValuePair <string, string>(x, x));
                }
            });

            // Handle duplicates
            var result = new Dictionary <string, string>();

            foreach (var x in sources)
            {
                result[x.Key] = x.Value;
            }

            return(result);
        }
Exemplo n.º 2
0
        internal static Dictionary <string, string> GetSourceNames(Serialization.Interface.IBackup backup)
        {
            var systemIO = Duplicati.Library.Snapshots.SnapshotUtility.SystemIO;

            return(backup.Sources.Distinct().Select(x => {
                var sp = SpecialFolders.TranslateToDisplayString(x);
                if (sp != null)
                {
                    return new KeyValuePair <string, string>(x, sp);
                }

                x = SpecialFolders.ExpandEnvironmentVariables(x);
                try {
                    var nx = x;
                    if (nx.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        nx = nx.Substring(0, nx.Length - 1);
                    }
                    var n = systemIO.PathGetFileName(nx);
                    if (!string.IsNullOrWhiteSpace(n))
                    {
                        return new KeyValuePair <string, string>(x, n);
                    }
                } catch {
                }

                if (x.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) && x.Length > 1)
                {
                    return new KeyValuePair <string, string>(x, x.Substring(0, x.Length - 1).Substring(x.Substring(0, x.Length - 1).LastIndexOf("/") + 1));
                }
                else
                {
                    return new KeyValuePair <string, string>(x, x);
                }
            }).ToDictionary(x => x.Key, x => x.Value));
        }