示例#1
0
        public void CompareTo(FS other, Action <FS.Entry> Addition, Action <FS.Entry> Removal, Action <Tuple <FS.Entry, FS.Entry> > Change)
        {
            entries.Sort();
            other.entries.Sort();

            List <Entry> Added   = new List <Entry>();
            List <Entry> Removed = new List <Entry>();
            List <Tuple <Entry, Entry> > Changed = new List <Tuple <Entry, Entry> >();

            int pos = 0, other_pos = 0;

            while (pos < entries.Count && other_pos < other.entries.Count)
            {
                FS.Entry elem       = entries[pos];
                FS.Entry other_elem = other.entries[other_pos];

                int order = elem.relative_path.CompareTo(other_elem.relative_path);

                if (order == 0)
                {
                    pos++;
                    other_pos++;
                    if (elem.CompareTo(other_elem) != 0)
                    {
                        Changed.Add(new Tuple <Entry, Entry>(elem, other_elem));
                    }
                }
                else if (order < 0)
                {
                    pos++;
                    Removed.Add(elem);
                }
                else
                {
                    other_pos++;
                    Added.Add(other_elem);
                }
            }

            while (pos < entries.Count)
            {
                Removed.Add(entries[pos++]);
            }

            while (other_pos < other.entries.Count)
            {
                Added.Add(other.entries[other_pos++]);
            }

            Added.ForEach(Addition);
            Removed.ForEach(Removal);
            Changed.ForEach(Change);
            Console.WriteLine((entries.Count + other.entries.Count).ToString() + " entries compared.");
        }
示例#2
0
            public void LoadAttributesFrom(FS.Entry other, bool preview)
            {
                //DateTime base_date = new DateTime(2012, 01, 07, 19, 0, 0);
                //if ((date_last_modified_utc - base_date).TotalDays > 1 && date_last_modified_utc > other.date_last_modified_utc) {
                if (date_last_modified_utc > other.date_last_modified_utc)
                {
                    Console.WriteLine(" Current file is more recent: not updating " + abs_path);
                    return;
                }

                Console.Write(" Updating " + abs_path + "... ");

                if (preview)
                {
                    Console.WriteLine("not done.");
                    return;
                }
                else
                {
                    try {
                        //IO.File.SetAttributes(abs_path, is_dir ? IO.FileAttributes.Directory : IO.FileAttributes.Normal); //Set attributes to normal first.
                        IO.File.SetAttributes(abs_path, other.attr);
                        if (is_dir)
                        {
                            IO.Directory.SetCreationTimeUtc(abs_path, other.date_created_utc);
                            IO.Directory.SetLastWriteTimeUtc(abs_path, other.date_last_modified_utc);
                            IO.Directory.SetLastAccessTimeUtc(abs_path, other.date_last_accessed_utc);
                        }
                        else
                        {
                            IO.File.SetCreationTimeUtc(abs_path, other.date_created_utc);
                            IO.File.SetLastWriteTimeUtc(abs_path, other.date_last_modified_utc);
                            IO.File.SetLastAccessTimeUtc(abs_path, other.date_last_accessed_utc);
                        }
                        Console.WriteLine("done.");
                    }
                    catch (System.UnauthorizedAccessException) {
                        Console.WriteLine("failed.");
                    }
                    catch (System.IO.IOException) {
                        Console.WriteLine("failed.");
                    }
                }
            }
示例#3
0
            public static void CompareAttributes(FS.Entry e1, FS.Entry e2)
            {
                int attr1 = (int)e1.attr, attr2 = (int)e2.attr;

                int added     = attr2 & (~attr1);
                int unchanged = attr1 & attr2;
                int removed   = attr1 & (~attr2);

                //Console.WriteLine(" -> " + Convert.ToString(attr1, 2).PadLeft(16, '0'));
                //Console.WriteLine(" -> " + Convert.ToString(attr2, 2).PadLeft(16, '0'));

                if (attr1 != attr2)
                {
                    Console.WriteLine(" Attributes:");

                    if (removed != 0)
                    {
                        Console.WriteLine("  - " + ((IO.FileAttributes)removed).ToString());
                    }

                    if (unchanged != 0)
                    {
                        Console.WriteLine("  = " + ((IO.FileAttributes)unchanged).ToString());
                    }

                    if (added != 0)
                    {
                        Console.WriteLine("  + " + ((IO.FileAttributes)added).ToString());
                    }
                }

                Action <string, DateTime, DateTime> CompareDates = (label, date1, date2) => {
                    if (date1 != date2)
                    {
                        Console.WriteLine(" " + label);
                        Console.WriteLine("  - " + date1.ToString("u"));
                        Console.WriteLine("  + " + date2.ToString("u"));
                    }
                };

                //CompareDates("Creation date:", e1.date_created, e2.date_created);
                CompareDates("Modification date:", e1.date_last_modified_utc, e2.date_last_modified_utc);
            }