Exemplo n.º 1
0
        /// <summary>
        /// Loads the files.
        /// </summary>
        /// <param name="reader">The log reader.</param>
        /// <param name="logs">The list to add open logs to.</param>
        /// <param name="files">The files too open.</param>
        /// <param name="initialVersion">The initial log version.</param>
        /// <param name="ignoreVersionChanges">If set to <c>true</c> version information in the log is ignored.</param>
        /// <param name="progress">The progress.</param>
        private void LoadFiles(ILogReader reader,
            ICollection<PacketLog> logs,
            string[] files,
            float initialVersion,
            bool ignoreVersionChanges,
            ProgressCallback progress)
        {
            foreach (string fileName in files)
            {
                try
                {
                    // Create new log for each file
                    PacketLog log = new PacketLog();
                    log.Version = initialVersion;
                    log.IgnoreVersionChanges = ignoreVersionChanges;

                    m_progress.SetDescription("Loading file: " + fileName + "...");

                    // Check if file exists
                    FileInfo fileInfo = new FileInfo(fileName);
                    if (!fileInfo.Exists)
                    {
                        Log.Info("File \"" + fileInfo.FullName + "\" doesn't exist, ignored.");
                        continue;
                    }

                    // Add all packets
                    using(FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        log.AddRange(reader.ReadLog(new BufferedStream(stream, 64*1024), progress));
                    }

                    // Initialize log
                    m_progress.SetDescription("Initializing log and packets...");
                    log.Init(LogManager, 3, progress);

                    // Set stream name
                    log.StreamName = fileInfo.FullName;

                    AddRecentFile(fileInfo.FullName);
                    logs.Add(log);
                }
                catch (Exception e)
                {
                    Log.Error("loading files", e);
                }
            }
        }