예제 #1
0
        public ExportResult Export(string path)
        {
            ExportResult result = new ExportResult();

            Logger.Current.Log(LogCategory.Configuration, Settings);

            if (!Directory.Exists(path))
            {
                Logger.Current.Log(LogCategory.CreateDirectory, path);
                Directory.CreateDirectory(path);
            }

            foreach (string srcPath in GetFiles(_srcPath))
            {
                string relativePath = GetRelativePath(srcPath);
                relativePath = ApplyReplacements(relativePath);
                string dstPath = Path.Combine(path, relativePath);
                if (Directory.Exists(srcPath))
                {
                    result.Directories++;

                    if (ReparsePoint.IsSymbolicLink(srcPath))
                    {
                        if (Settings.KeepSymbolicLinks)
                        {
                            string link = ReparsePoint.GetTargetDir(new DirectoryInfo(srcPath));
                            ReparsePoint.CreateSymbolicLink(dstPath, link, SymbolicLinkType.Directory);
                            continue;
                        }
                    }

                    if (!Directory.Exists(dstPath))
                    {
                        Directory.CreateDirectory(dstPath);
                    }
                }
                else
                {
                    result.Files++;

                    if (ReparsePoint.IsSymbolicLink(srcPath))
                    {
                        if (Settings.KeepSymbolicLinks)
                        {
                            string link = ReparsePoint.GetTargetDir(new FileInfo(srcPath));
                            ReparsePoint.CreateSymbolicLink(dstPath, link, SymbolicLinkType.File);
                            continue;
                        }
                    }

                    CopyFile(srcPath, dstPath);
                }
            }

            return(result);
        }
예제 #2
0
        private static void SafeMain(string[] args)
        {
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
                return;
            }

            CodeFluent.Runtime.Diagnostics.ConsoleListener.EnsureConsole();

            if (args.Any(s => s == "/?" || s == "-?"))
            {
                PrintUsage();
                return;
            }

            if (Trace.Listeners.Count == 0 || (Trace.Listeners.Count == 1 && Trace.Listeners[0].GetType() == typeof(DefaultTraceListener)))
            {
                Trace.Listeners.Add(new ConsoleTraceListener());
            }

            Settings settings;

            if (args.Length > 2)
            {
                settings = Settings.Deserialize(args[2]);
            }
            else
            {
                settings = Settings.GetDefault();
            }

            //XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            //using (Stream s = File.OpenWrite("settings.xml"))
            //    serializer.Serialize(s, settings);

            Exporter     exporter = new Exporter(args[0], settings);
            ExportResult result   = exporter.Export(args[1]);

            Logger.Current.Log(LogCategory.Summary, "Directories: " + result.Directories);
            Logger.Current.Log(LogCategory.Summary, "Files:       " + result.Files);
        }