Example #1
0
 static bool HasNoSource(StupidLogger log, Counter counter, Dictionary<string, List<FileInfo>> dst_files, string filename, Dictionary<string, List<FileInfo>> src_files)
 {
     if (!src_files.ContainsKey(filename))
     {
         counter.Unsourced++;
         log.Write("No source: ");
         foreach (var filespec in dst_files[filename]) log.Write(filespec.FullName + "; ");
         log.Write("\r\n");
         return true;
     }
     return false;
 }
Example #2
0
        static void Main(string[] args)
        {
            var settings = new ArgumentParser().Read(args);

            if (!Directory.Exists(settings.BasePath))
            {
                ShowPathMessage(settings.BasePath);
                return;
            }

            var log = new StupidLogger(settings.LogPath);
            var root_path = new DirectoryInfo(settings.BasePath);
            var counter = new Counter();

            SyncroniseDependencies(log, settings, root_path, counter);

            Console.WriteLine(counter);
        }
Example #3
0
        static void UpdateDestinations(StupidLogger log, Counter counter, FileInfo newest_source, IEnumerable<FileInfo> match_list)
        {
            foreach (var potential_destination in match_list)
            {
                if (potential_destination == newest_source) throw new Exception("Source was a dependency! Check your src and dst patterns don't overlap.");

                counter.Copies++;
                try
                {
                    File.Copy(newest_source.FullName, potential_destination.FullName, true);
                }
                catch
                {
                    log.Write("Failed to overwrite \"" + potential_destination.FullName + "\" with \"" + newest_source.FullName + "\"");
                    counter.Fails++;
                }
            }
        }
Example #4
0
        static void SyncroniseDependencies(StupidLogger log, ArgumentParser settings, DirectoryInfo root_path, Counter counter)
        {
            var masters = FindMasters(settings.Masters, root_path);
            var src_files = FindMatches(settings.SourcePattern, root_path);
            var dst_files = FindMatches(settings.DestPattern, root_path);

            foreach (var filename in dst_files.Keys)
            {
                var match_list = dst_files[filename];
                if (match_list == null || match_list.Count < 1) continue;

                if (HasNoSource(log, counter, dst_files, filename, src_files)) continue;

                var newest_source = masters.Of(filename) ?? newest(src_files[filename]);
                if (settings.Verbose) log.Write("Chose: "+newest_source.FullName);

                UpdateDestinations(log, counter, newest_source, match_list);
            }
        }