Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Usage();
            }
            else
            {
                string filename = Path.GetFullPath(args[0]);

                using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    Type dataType = FormatUtil.getObjectType(fs);

                    if (dataType != null)
                    {
                        string tagHashValue;
                        char[] trimNull = new char[] { '\0' };

                        // initialize data
                        IFormat vgmData = (IFormat)Activator.CreateInstance(dataType);
                        vgmData.Initialize(fs, filename);
                        Dictionary <string, string> tagHash = vgmData.GetTagHash();

                        // loop over hash and output information
                        foreach (string s in tagHash.Keys)
                        {
                            tagHashValue = tagHash[s];

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

                            Console.WriteLine(s + ": " + tagHashValue);
                        }
                    }
                }
            }
        }
        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);
        }