Ejemplo n.º 1
0
        public static State GetCurrentState(string path, Connection share)
        {
            if (share.isChanged == false &&
                share.CurrentState.Files.Count > 0 &&
                share.CurrentState.Folders.Count > 0)
            {
                return(share.CurrentState);
            }

            DateTime dt    = FastDateTime.Now;
            State    state = new State();

            foreach (var f in LongDirectory.GetDirectories(path, "*.*", SearchOption.AllDirectories))
            {
                string p = f.Replace(path, "")
                           .Replace("/", "\\"); // for unix systems
                if (share.Allowed(p))
                {
                    state.Folders.Add(p);
                }
            }

            if (Global.isWindows == false)
            {
                foreach (var f in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
                {
                    var    fi = new FileInfo(f);
                    string fn = fi.FullName.Replace(path, "")
                                .Replace("/", "\\"); // for unix systems
                    if (share.Allowed(fi.FullName))
                    {
                        state.Files.Add(new SyncFile {
                            F = fn, D = fi.LastWriteTime, S = fi.Length
                        });
                    }
                }
            }
            else
            {
                foreach (var f in FastDirectoryEnumerator.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
                {
                    string fn = f.Path.Replace(path, "")
                                .Replace("/", "\\"); // for unix systems
                    if (share.Allowed(f.Path))
                    {
                        state.Files.Add(new SyncFile {
                            F = fn, D = f.LastWriteTime, S = f.Size
                        });
                    }
                }
            }
            _log.Info("GetCurrentState total secs = " + FastDateTime.Now.Subtract(dt).TotalSeconds);
            share.CurrentState = state;
            return(state);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets <see cref="FileData"/> for all the files in a directory that match a
        /// specific filter.
        /// </summary>
        /// <param name="path">The path to search.</param>
        /// <param name="searchPattern">The search string to match against files in the path.</param>
        /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
        /// allows you to enumerate the files in the given directory.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="path"/> is a null reference (Nothing in VB)
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="filter"/> is a null reference (Nothing in VB)
        /// </exception>
        public static FileData[] GetFiles(string path, string searchPattern, SearchOption searchOption)
        {
            IEnumerable <FileData> e    = FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, searchOption);
            List <FileData>        list = new List <FileData>(e);

            FileData[] retval = new FileData[list.Count];
            list.CopyTo(retval);
            list.Clear();
            list = null;
            return(retval);
        }
Ejemplo n.º 3
0
        // TODO : better handling of locked files
        public QueueProcessor(string path, Connection connection)
        {
            _path    = path;
            _conn    = connection;
            _quefile = _path + _conn.Name + ".queue";

            string archivefolder = _conn.Path + ".ts" + _S + "old" + _S;

            Directory.CreateDirectory(archivefolder);

            if (Directory.Exists(_conn.Path + ".ts" + _S + "Temp"))
            {
                Directory.Delete(_conn.Path + ".ts" + _S + "Temp", true);
            }

            if (File.Exists(_conn.Path + ".ts" + _S + "readme.txt") == false)
            {
                File.WriteAllText(_conn.Path + ".ts" + _S + "readme.txt", "This is the TorpedoSync folder for old archived files and settings.");
            }

            if (File.Exists(_conn.Path + ".ts" + _S + ".ignore") == false)
            {
                File.WriteAllText(_conn.Path + ".ts" + _S + ".ignore", "# comment line\r\n");
            }

            // cleanup failed .!torpedosync files
            if (TorpedoSync.Global.isWindows == true)
            {
                foreach (var i in FastDirectoryEnumerator.EnumerateFiles(_conn.Path, "*.!torpedosync", SearchOption.AllDirectories))
                {
                    LongFile.Delete(i.Path);
                }
            }
            else
            {
                //foreach (var i in Directory.EnumerateFiles(_conn.Path, "*.!torpedosync", SearchOption.AllDirectories))
                //    LongFile.Delete(i);
            }
            _timer.AutoReset = true;
            _timer.Elapsed  += timer_elapsed;
            _timer.Start();
            LoadQueue();
            StartWatcher();
            Task.Factory.StartNew(DoWork);
            Task.Factory.StartNew(() => { timer_elapsed(null, null); });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets <see cref="FileData"/> for all the files in a directory that match a
 /// specific filter.
 /// </summary>
 /// <param name="path">The path to search.</param>
 /// <param name="searchPattern">The search string to match against files in the path.</param>
 /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
 /// allows you to enumerate the files in the given directory.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="path"/> is a null reference (Nothing in VB)
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="filter"/> is a null reference (Nothing in VB)
 /// </exception>
 public static IEnumerable <FileData> EnumerateFiles(string path, string searchPattern)
 {
     return(FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets <see cref="FileData"/> for all the files in a directory.
 /// </summary>
 /// <param name="path">The path to search.</param>
 /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
 /// allows you to enumerate the files in the given directory.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="path"/> is a null reference (Nothing in VB)
 /// </exception>
 public static IEnumerable <FileData> EnumerateFiles(string path)
 {
     return(FastDirectoryEnumerator.EnumerateFiles(path, "*"));
 }