Ejemplo n.º 1
0
        private void AddFile(ZetaLongPaths.ZlpFileInfo file)
        {
            CancellationToken.ThrowIfCancellationRequested();

            try
            {
                // IMPORTANT: The condition below, `if (!file.Exists)`, doesn't guarantee the
                // file will exist after this statement! We probably shouldn't try to detect this but
                // handle any exceptions that may be raised.
                if (!file.Exists)
                {
                    // FileInfo.FullName may throw:
                    //    System.IO.PathTooLongException
                    //    System.Security.SecurityException
                    logger.Warn("File {0} does not exist", file.FullName);
                    return;
                }

                var item = file.FullName;

                // IMPORTANT: Strip the \\?\ prefix Windows uses for long paths (those > MAX_PATH).
                if (item != null && item.StartsWith(@"\\?\"))
                {
                    item = item.Substring(4);
                }

                Results.AddedFile(item);

                if (FileAdded != null)
                {
                    FileAdded(this, item);
                }
            }
            catch (OperationCanceledException)
            {
                throw;                 // Rethrow!
            }
            catch (Exception ex)
            {
                HandleException(EntryType.FILE, file.FullName, ex);
            }
        }