Exemplo n.º 1
0
        public static void Main(string[] _args)
        {
            List <string> args = new List <string>(_args);
            Dictionary <string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
            Options opt = new Options();

            foreach (FieldInfo fi in opt.GetType().GetFields())
            {
                if (options.ContainsKey(fi.Name))
                {
                    fi.SetValue(opt, options[fi.Name]);
                }
            }

            opt.Fixup();

            Duplicati.Library.Utility.IFilter filter = null;
            if (!string.IsNullOrEmpty(opt.ignorefilter))
            {
                filter = new Duplicati.Library.Utility.FilterExpression(opt.ignorefilter, false);
            }

            var paths = Duplicati.Library.Utility.Utility.EnumerateFileSystemEntries(opt.sourcefolder, filter).Select(x => x.Substring(opt.sourcefolder.Length));

            //A bit backwards, but we have flattend the file list, and now we re-construct the tree,
            // but we do not care much about performance here
            RootFolderInfo rootfolder = new RootFolderInfo(opt, paths);

            new XDocument(
                new XElement(XWIX + "Wix",
                             new XElement(XWIX + "Fragment",
                                          rootfolder.GroupNode,
                                          new XElement(XWIX + "DirectoryRef",
                                                       new XAttribute("Id", opt.dirref),
                                                       rootfolder.Node
                                                       )
                                          )
                             )
                ).Save(opt.outputfile);

            WriteKeyDatabase(rootfolder.GeneratedKeys, opt.dbfilename, true);

            Console.WriteLine("Generated wxs: {0}", opt.outputfile);
        }
Exemplo n.º 2
0
        public static int List(List <string> args, Dictionary <string, string> options, Library.Utility.IFilter filter)
        {
            filter = filter ?? new Duplicati.Library.Utility.FilterExpression();
            if (Duplicati.Library.Utility.Utility.ParseBoolOption(options, "list-sets-only"))
            {
                filter = new Duplicati.Library.Utility.FilterExpression();
            }

            using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
            {
                var backend = args[0];
                args.RemoveAt(0);

                if (args.Count == 1)
                {
                    long v;
                    if (long.TryParse(args[0], out v))
                    {
                        if (!options.ContainsKey("version"))
                        {
                            args.RemoveAt(0);
                            args.Add("*");
                            options["version"] = v.ToString();
                        }
                    }
                    else if (args[0].IndexOfAny(new char[] { '*', '?' }) < 0 && !args[0].StartsWith("["))
                    {
                        try
                        {
                            var t = Library.Utility.Timeparser.ParseTimeInterval(args[0], DateTime.Now, true);
                            args.RemoveAt(0);
                            args.Add("*");
                            options["time"] = t.ToString();
                        }
                        catch
                        {
                        }
                    }
                }

                // Prefix all filenames with "*/" so we search all folders
                for (var ix = 0; ix < args.Count; ix++)
                {
                    if (args[ix].IndexOfAny(new char[] { '*', '?', System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }) < 0 && !args[ix].StartsWith("["))
                    {
                        args[ix] = "*" + System.IO.Path.DirectorySeparatorChar.ToString() + args[ix];
                    }
                }

                // Support for not adding the --auth-username if possible
                string dbpath;
                options.TryGetValue("dbpath", out dbpath);
                if (string.IsNullOrEmpty(dbpath))
                {
                    dbpath = Library.Main.DatabaseLocator.GetDatabasePath(backend, new Duplicati.Library.Main.Options(options), false, true);
                    if (dbpath != null)
                    {
                        options["dbpath"] = dbpath;
                    }
                }

                // Don't ask for passphrase if we have a local db
                if (!string.IsNullOrEmpty(dbpath) && System.IO.File.Exists(dbpath) && !options.ContainsKey("no-encryption") && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "no-local-db"))
                {
                    string passphrase;
                    options.TryGetValue("passphrase", out passphrase);
                    if (string.IsNullOrEmpty(passphrase))
                    {
                        options["no-encryption"] = "true";
                    }
                }


                bool controlFiles = Library.Utility.Utility.ParseBoolOption(options, "control-files");
                options.Remove("control-files");

                var res = controlFiles ? i.ListControlFiles(args, filter) : i.List(args, filter);

                //If there are no files matching, and we are looking for one or more files,
                // try again with all-versions set
                var isRequestForFiles =
                    !controlFiles && res.Filesets.Count() != 0 &&
                    (res.Files == null || res.Files.Count() == 0) &&
                    !filter.Empty;

                if (isRequestForFiles && !Library.Utility.Utility.ParseBoolOption(options, "all-versions"))
                {
                    Console.WriteLine("No files matching, looking in all versions");
                    options["all-versions"] = "true";
                    options.Remove("time");
                    options.Remove("version");
                    res = i.List(args, filter);
                }

                if (res.Filesets.Count() != 0 && (res.Files == null || res.Files.Count() == 0) && filter.Empty)
                {
                    Console.WriteLine("Listing filesets:");

                    foreach (var e in res.Filesets)
                    {
                        if (e.FileCount >= 0)
                        {
                            Console.WriteLine("{0}\t: {1} ({2} files, {3})", e.Version, e.Time, e.FileCount, Library.Utility.Utility.FormatSizeString(e.FileSizes));
                        }
                        else
                        {
                            Console.WriteLine("{0}\t: {1}", e.Version, e.Time);
                        }
                    }
                }
                else
                {
                    if (res.Filesets.Count() == 0)
                    {
                        Console.WriteLine("No time or version matched a fileset");
                    }
                    else if (res.Files == null || res.Files.Count() == 0)
                    {
                        Console.WriteLine("Found {0} filesets, but no files matched", res.Filesets.Count());
                    }
                    else if (res.Filesets.Count() == 1)
                    {
                        var f = res.Filesets.First();
                        Console.WriteLine("Listing contents {0} ({1}):", f.Version, f.Time);
                        foreach (var e in res.Files)
                        {
                            Console.WriteLine("{0} {1}", e.Path, e.Path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) ? "" : "(" + Library.Utility.Utility.FormatSizeString(e.Sizes.First()) + ")");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Listing files and versions:");
                        foreach (var e in res.Files)
                        {
                            Console.WriteLine(e.Path);
                            foreach (var nx in res.Filesets.Zip(e.Sizes, (a, b) => new { Index = a.Version, Time = a.Time, Size = b }))
                            {
                                Console.WriteLine("{0}\t: {1} {2}", nx.Index, nx.Time, nx.Size < 0 ? " - " : Library.Utility.Utility.FormatSizeString(nx.Size));
                            }

                            Console.WriteLine();
                        }
                    }
                }
            }

            return(0);
        }
Exemplo n.º 3
0
        public static void Main(string[] _args)
        {
            List <string> args = new List <string>(_args);
            Dictionary <string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
            Options opt = new Options();

            foreach (FieldInfo fi in opt.GetType().GetFields())
            {
                if (options.ContainsKey(fi.Name))
                {
                    fi.SetValue(opt, options[fi.Name]);
                }
            }

            opt.Fixup();

            Duplicati.Library.Utility.IFilter filter = null;
            if (!string.IsNullOrEmpty(opt.ignorefilter))
            {
                filter = new Duplicati.Library.Utility.FilterExpression(opt.ignorefilter, false);
            }

            Func <string, bool> isFile = (string x) => !x.EndsWith(DIR_SEP);

            var paths = Duplicati.Library.Utility.Utility.EnumerateFileSystemEntries(opt.sourcefolder, filter)
                        .Where(x => isFile(x) && FILEMAP.ContainsKey(Path.GetFileName(x)))
                        .Select(x =>
            {
                var m = FILEMAP[Path.GetFileName(x)].Match(File.ReadAllText(x));
                return(m.Success ?
                       new { File = x, Version = new Version(m.Groups["version"].Value.Replace("*", "0")), Display = m.Groups["version"].Value }
                        : null);
            })
                        .Where(x => x != null)
                        .ToArray(); //No need to re-eval

            if (paths.Count() == 0)
            {
                Console.WriteLine("No files found to update...");
                return;
            }

            foreach (var p in paths)
            {
                Console.WriteLine("{0}\t:{1}", p.Display, p.File);
            }

            if (string.IsNullOrWhiteSpace(opt.version))
            {
                var maxv = paths.Select(x => x.Version).Max();
                opt.version = new Version(
                    maxv.Major,
                    maxv.Minor,
                    maxv.Build,
                    maxv.Revision).ToString();
            }

            //Sanity check
            var nv = new Version(opt.version).ToString(4);

            foreach (var p in paths)
            {
                var re  = FILEMAP[Path.GetFileName(p.File)];
                var txt = File.ReadAllText(p.File);
                //var m = re.Match(txt).Groups["version"];
                txt = re.Replace(txt, (m) => {
                    var t = m.Groups["version"];
                    return(m.Value.Replace(t.Value, nv));
                });
                File.WriteAllText(p.File, txt);
            }

            Console.WriteLine("Updated {0} files to version {1}", paths.Count(), opt.version);
        }
Exemplo n.º 4
0
		public static void Main (string[] _args)
		{			
			List<string> args = new List<string>(_args);
			Dictionary<string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
			Options opt = new Options();
			
			foreach(FieldInfo fi in opt.GetType().GetFields())
				if (options.ContainsKey(fi.Name))
					fi.SetValue(opt, options[fi.Name]);
			
			opt.Fixup();			
			
            Duplicati.Library.Utility.IFilter filter = null;
			if (!string.IsNullOrEmpty(opt.ignorefilter))
                filter = new Duplicati.Library.Utility.FilterExpression(opt.ignorefilter, false);
			
            var paths = Duplicati.Library.Utility.Utility.EnumerateFileSystemEntries(opt.sourcefolder, filter).Select(x => x.Substring(opt.sourcefolder.Length));

			//A bit backwards, but we have flattend the file list, and now we re-construct the tree,
			// but we do not care much about performance here
			RootFolderInfo rootfolder = new RootFolderInfo(opt, paths);
			
			new XDocument(
				new XElement(XWIX + "Wix",
					new XElement(XWIX + "Fragment",
			            rootfolder.GroupNode,
						new XElement(XWIX + "DirectoryRef",
							new XAttribute("Id", opt.dirref),
			             	rootfolder.Node
						)
					)
				)
			).Save(opt.outputfile);

			WriteKeyDatabase(rootfolder.GeneratedKeys, opt.dbfilename, true);
			
			Console.WriteLine("Generated wxs: {0}", opt.outputfile);
			
		}
Exemplo n.º 5
0
        public static int List(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
        {
            filter = filter ?? new Duplicati.Library.Utility.FilterExpression();
            if (Duplicati.Library.Utility.Utility.ParseBoolOption(options, "list-sets-only"))
                filter = new Duplicati.Library.Utility.FilterExpression();

            using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
            {
                var backend = args[0];
                args.RemoveAt(0);
                                
                if (args.Count == 1)
                {
                    long v;
                    if (long.TryParse(args[0], out v))
                    {
                        if (!options.ContainsKey("version"))
                        {
                            args.RemoveAt(0);
                            args.Add("*");
                            options["version"] = v.ToString();
                        }
                    }
                    else if (args[0].IndexOfAny(new char[] { '*', '?' }) < 0 && !args[0].StartsWith("["))
                    {
                        try
                        {
                            var t = Library.Utility.Timeparser.ParseTimeInterval(args[0], DateTime.Now, true);
                            args.RemoveAt(0);
                            args.Add("*");
                            options["time"] = t.ToString();
                        }
                        catch
                        {
                        }
                    }
                }
                
                // Prefix all filenames with "*/" so we search all folders
                for(var ix = 0; ix < args.Count; ix++) 
                    if (args[ix].IndexOfAny(new char[] { '*', '?', System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }) < 0 && !args[ix].StartsWith("["))
                        args[ix] = "*" + System.IO.Path.DirectorySeparatorChar.ToString() + args[ix];
                
                // Support for not adding the --auth-username if possible
                string dbpath;
                options.TryGetValue("dbpath", out dbpath);
                if (string.IsNullOrEmpty(dbpath))
                {
                    dbpath = Library.Main.DatabaseLocator.GetDatabasePath(backend, new Duplicati.Library.Main.Options(options), false, true);
                    if (dbpath != null)
                        options["dbpath"] = dbpath;
                }

                // Don't ask for passphrase if we have a local db
                if (!string.IsNullOrEmpty(dbpath) && System.IO.File.Exists(dbpath) && !options.ContainsKey("no-encryption") && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "no-local-db"))
                {
                    string passphrase;
                    options.TryGetValue("passphrase", out passphrase);
                    if (string.IsNullOrEmpty(passphrase))
                        options["no-encryption"] = "true";
                }

            
                bool controlFiles = Library.Utility.Utility.ParseBoolOption(options, "control-files");
                options.Remove("control-files");
                
                var res = controlFiles ? i.ListControlFiles(args, filter) : i.List(args, filter);

                //If there are no files matching, and we are looking for one or more files, 
                // try again with all-versions set
                var compareFilter = Library.Utility.JoinedFilterExpression.Join(new Library.Utility.FilterExpression(args), filter);
                var isRequestForFiles = 
                    !controlFiles && res.Filesets.Count() != 0 && 
                    (res.Files == null || res.Files.Count() == 0) && 
                    !compareFilter.Empty;
                
                if (isRequestForFiles && !Library.Utility.Utility.ParseBoolOption(options, "all-versions"))
                {
                    Console.WriteLine("No files matching, looking in all versions");
                    options["all-versions"] = "true";
                    options.Remove("time");
                    options.Remove("version");
                    res = i.List(args, filter);
                }

                if (res.Filesets.Count() != 0 && (res.Files == null || res.Files.Count() == 0) && compareFilter.Empty)
                {
                    Console.WriteLine("Listing filesets:");
                    
                    foreach(var e in res.Filesets)
                    {
                        if (e.FileCount >= 0)
                            Console.WriteLine("{0}\t: {1} ({2} files, {3})", e.Version, e.Time, e.FileCount, Library.Utility.Utility.FormatSizeString(e.FileSizes));
                        else
                            Console.WriteLine("{0}\t: {1}", e.Version, e.Time);
                    }
                }
                else if (isRequestForFiles)
                {
                    Console.WriteLine("No files matched expression");
                }
                else
                {
                    if (res.Filesets.Count() == 0)
                    {
                        Console.WriteLine("No time or version matched a fileset");
                    }
                    else if (res.Files == null || res.Files.Count() == 0)
                    {
                        Console.WriteLine("Found {0} filesets, but no files matched", res.Filesets.Count());
                    }
                    else if (res.Filesets.Count() == 1)
                    {
                        var f = res.Filesets.First();
                        Console.WriteLine("Listing contents {0} ({1}):", f.Version, f.Time);
                        foreach(var e in res.Files)
                            Console.WriteLine("{0} {1}", e.Path, e.Path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) ? "" : "(" + Library.Utility.Utility.FormatSizeString(e.Sizes.First()) + ")");
                    }
                    else
                    {
                        Console.WriteLine("Listing files and versions:");
                        foreach(var e in res.Files)
                        {
                            Console.WriteLine(e.Path);
                            foreach(var nx in res.Filesets.Zip(e.Sizes, (a, b) => new { Index = a.Version, Time = a.Time, Size = b } ))
                                Console.WriteLine("{0}\t: {1} {2}", nx.Index, nx.Time, nx.Size < 0 ? " - " : Library.Utility.Utility.FormatSizeString(nx.Size));
                                
                            Console.WriteLine();
                        }
                        
                    }
                }
            }
            
            return 0;
        }
Exemplo n.º 6
0
        public static void Main(string[] _args)
        {
            List<string> args = new List<string>(_args);
            Dictionary<string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
            Options opt = new Options();
            
            foreach (FieldInfo fi in opt.GetType().GetFields())
                if (options.ContainsKey(fi.Name))
                    fi.SetValue(opt, options[fi.Name]);
            
            opt.Fixup();            
            
            Duplicati.Library.Utility.IFilter filter = null;
            if (!string.IsNullOrEmpty(opt.ignorefilter))
                filter = new Duplicati.Library.Utility.FilterExpression(opt.ignorefilter, false);
            
            Func<string, bool> isFile = (string x) => !x.EndsWith(DIR_SEP);
            
            var paths = Duplicati.Library.Utility.Utility.EnumerateFileSystemEntries(opt.sourcefolder, filter)
                .Where(x => isFile(x) && FILEMAP.ContainsKey(Path.GetFileName(x)))
                .Select(x =>
            {
                var m = FILEMAP[Path.GetFileName(x)].Match(File.ReadAllText(x));
                return m.Success ? 
                        new { File = x, Version = new Version(m.Groups["version"].Value.Replace("*", "0")), Display = m.Groups["version"].Value } 
                        : null;
            })
                .Where(x => x != null)
                .ToArray(); //No need to re-eval
            
            if (paths.Count() == 0)
            {
                Console.WriteLine("No files found to update...");
                return;
            }
            
            foreach (var p in paths)
                Console.WriteLine("{0}\t:{1}", p.Display, p.File);
            
            if (string.IsNullOrWhiteSpace(opt.version))
            {
                var maxv = paths.Select(x => x.Version).Max();
                opt.version = new Version(
                    maxv.Major,
                    maxv.Minor,
                    maxv.Build,
                    maxv.Revision).ToString();
            }
            
            //Sanity check
            var nv = new Version(opt.version).ToString(4);

            foreach (var p in paths)
            {
                var re = FILEMAP[Path.GetFileName(p.File)];
                var txt = File.ReadAllText(p.File);
                //var m = re.Match(txt).Groups["version"];
                txt = re.Replace(txt, (m) => {
                    var t = m.Groups["version"];
                    return m.Value.Replace(t.Value, nv);
                });
                File.WriteAllText(p.File, txt);
            }

            Console.WriteLine("Updated {0} files to version {1}", paths.Count(), opt.version);
        }