示例#1
0
        private TreeNode getFileNode(string pFileName, StreamWriter pOutputFileStream,
                                     bool pCheckForLibs, DoWorkEventArgs e)
        {
            int progress = (++fileCount * 100) / maxFiles;

            this.progressStruct.Clear();
            this.progressStruct.FileName = pFileName;
            ReportProgress(progress, this.progressStruct);

            TreeNode ret = new TreeNode(Path.GetFileName(pFileName));

            VGMToolbox.util.NodeTagStruct nodeTag = new VGMToolbox.util.NodeTagStruct();
            TreeNode tagNode;
            string   tagHashValue = String.Empty;

            using (FileStream fs = File.OpenRead(pFileName))
            {
                try
                {
                    Type dataType = FormatUtil.getObjectType(fs);

                    if (dataType != null)
                    {
                        pOutputFileStream.WriteLine(pFileName);

                        IFormat vgmData = (IFormat)Activator.CreateInstance(dataType);
                        vgmData.Initialize(fs, pFileName);
                        Dictionary <string, string> tagHash = vgmData.GetTagHash();

                        // Add Path for possible future use.
                        tagHash.Add("Path", vgmData.FilePath);

                        // check for libs
                        if (pCheckForLibs && vgmData.UsesLibraries())
                        {
                            if (!vgmData.IsLibraryPresent())
                            {
                                ret.ForeColor = Color.Red;
                                ret.Text     += " (Missing Library)";
                            }
                        }

                        char[] trimNull = new char[] { '\0' };

                        foreach (string s in tagHash.Keys)
                        {
                            tagHashValue = tagHash[s];

                            if (!String.IsNullOrEmpty(tagHashValue))
                            {
                                tagHashValue = tagHashValue.TrimEnd(trimNull);
                            }
                            else
                            {
                                tagHashValue = String.Empty;
                            }

                            tagNode = new TreeNode(s + ": " + tagHashValue);
                            ret.Nodes.Add(tagNode);

                            pOutputFileStream.WriteLine(s + ": " + tagHashValue);
                        }

                        pOutputFileStream.WriteLine(Environment.NewLine);

                        // add classname to nodeTag
                        nodeTag.ObjectType = dataType.AssemblyQualifiedName;
                    }
                }
                catch (Exception ex)
                {
                    this.progressStruct.Clear();
                    this.progressStruct.ErrorMessage = String.Format("Error processing <{0}>.  Error received: ", pFileName) + ex.Message;
                    ReportProgress(progress, this.progressStruct);
                }
            } // using (FileStream fs = File.OpenRead(pFileName))

            nodeTag.FilePath = pFileName;
            ret.Tag          = nodeTag;

            return(ret);
        }