コード例 #1
0
ファイル: bepref.cs プロジェクト: rlittletht/bedu
 public BEPref(BEList belSelection, BEList belExclusions, string sProgramDir)
 {
     m_nMaxDepth = 2;
     m_fReportZeros = true;
     m_fVerbose = false;
     m_fDoExclusions = false;
     m_belExclusions = belExclusions;
     m_belSelection = belSelection;
     m_sProgramDir = sProgramDir;
 }
コード例 #2
0
ファイル: bedir.cs プロジェクト: rlittletht/bedu
        /* G E T  D I R  S I Z E */
        /*----------------------------------------------------------------------------
            %%Function: GetDirSize
            %%Qualified: bedu.BEDir.GetDirSize
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public void ProcessDir(BEList belExclusions, BEList belInclusions, int cLevel, BEPref bep, IReportUsage iru)
        {
            if (m_plbed == null)
                PopulateDir();

            // at this point, we have populated (either because we were preloaded or we just loaded
            iru.OpenDir(m_sLabel, m_sFullPath);

            m_cbDirSize = 0;
            m_cbDirExcl = 0;

            foreach (BEDir bed in m_plbed)
                {
                bed.ProcessDir(belExclusions, belInclusions, cLevel + 1, bep, iru);
                m_cbDirSize += bed.DirSize;
                m_cbDirExcl += bed.DirExcl;
                }

            foreach (BEFile bef in m_plbef)
                {
                string sFullName = bef.FullName;
                if (bep.DoExclusions)
                    {
                    if ((belExclusions != null && belExclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or))
                        || (belInclusions != null && !belInclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or)))
                        {
                        iru.ReportFile(0, bef.Bytes, m_sLabel, sFullName);

                        m_cbDirExcl += bef.Bytes;
                        continue;
                        }
                    }

                iru.ReportFile(bef.Bytes, 0, m_sLabel, sFullName);

                m_cbDirSize += bef.Bytes;
                }

            iru.ReportDir(m_cbDirSize, m_cbDirExcl, m_sLabel, cLevel);
            iru.CloseDir();
        }
コード例 #3
0
ファイル: bedu.cs プロジェクト: rlittletht/bedu
        static void Main(string[] args)
        {
            UnitTest();
            string sError;

            CmdLineConfig clcfg = new CmdLineConfig(new CmdLineSwitch[]
                {
                    new CmdLineSwitch("r", false, false, "record to a file", "filename", null),
                    new CmdLineSwitch("f", true, false, "fast mode", null, null),
                    new CmdLineSwitch("p", false, false, "playback from a file", "filename", null),
                    new CmdLineSwitch("n", false, false, "name this server (for later playback)", "servername", null),
                    new CmdLineSwitch("h", false, false, "name this server share (for later playback)", "sharename", null),
                    new CmdLineSwitch("v", true, false, "verbose - show each file", null, null),
                    new CmdLineSwitch("z", true, false, "zeros - show directories that are 0 size", null, null),
                    new CmdLineSwitch("d", false, false, "depth - max depth to show", "depth", null),
                    new CmdLineSwitch("0", true, false, "depth 0 - alias for -d 0", null, null),
                    new CmdLineSwitch("1", true, false, "depth 0 - alias for -d 1", null, null),
                    new CmdLineSwitch("2", true, false, "depth 0 - alias for -d 2", null, null),
                    new CmdLineSwitch("3", true, false, "depth 0 - alias for -d 3", null, null),
                    new CmdLineSwitch("x", true, false, "exclusions - use the global exclusion list", null, null),
                    new CmdLineSwitch("X", false, false, "eXclusions - load more exclusions from the named file", "filename", null),
                    new CmdLineSwitch("i", false, false, "inclusions - this is the selection list to match against", "filename", null)
                } );
            BEList belExclusions = new BEList();
            BEList belSelection = new BEList();
            BEDir bedProgram = new BEDir(Assembly.GetExecutingAssembly().Location, "");
            BEPref bep = new BEPref(belSelection, belExclusions, bedProgram.Dir);

            bep.MaxDepth=2;

            CmdLine cl = new CmdLine(clcfg);

            if (!cl.FParse(args, bep, null, out sError))
                {
                Console.WriteLine(sError);
                cl.Usage(OutputLine);
                return;
                }

            if (belSelection.Empty)
                belSelection = null;

            BEDir bedRoot = new BEDir(Environment.CurrentDirectory + @"\", ".");	// make sure we append a "/" because otherwise we won't know its a directory

            long cBytesExcl;

            //            bedRoot.GetDirSize(".", bedRoot.DirInfo, belExclusions, null, 0, bep, out cBytesExcl);
            // are we recording, playing back, or what?
            IReportUsage iru;
            if (bep.Fast)
                {
                iru = new ConsoleReportUsage(bep);
                BEDir.GetDirSizeFromDirectoryInfo(".", bedRoot.DirInfo, belExclusions, belSelection, 0, bep, iru, out cBytesExcl);
                }
            else
                {
                if (bep.Playback)
                    {
                    bedRoot = BedFromXml(XmlReader.Create(new StreamReader(bep.RecordFile)), bep);
                    // load the file here...
                    }

                if (bep.Record)
                    {
                    iru = new RecordReportUsage(bep, bep.ServerName, bep.ServerShare);
                    }
                else
                    {
                    iru = new ConsoleReportUsage(bep);
                    }

                iru.WritePrologue();
                bedRoot.ProcessDir(belExclusions, belSelection, 0, bep, iru);
                iru.WriteEpilogue();
                iru.Flush();
                }
        }
コード例 #4
0
ファイル: bedir.cs プロジェクト: rlittletht/bedu
        /* G E T  D I R  S I Z E  F R O M  D I R E C T O R Y  I N F O */
        /*----------------------------------------------------------------------------
            %%Function: GetDirSizeFromDirectoryInfo
            %%Qualified: bedu.BEDir.GetDirSizeFromDirectoryInfo
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public static long GetDirSizeFromDirectoryInfo(string sLabel, DirectoryInfo di, BEList belExclusions, BEList belInclusions, int cLevel, BEPref bep, IReportUsage iru, out long cBytesExcl)
        {
            long cBytes = 0;
            cBytesExcl = 0;

            iru.OpenDir(sLabel, di.FullName);

            DirectoryInfo []rgdi = null;

            // first, find any directories
            try
            {
                rgdi = di.GetDirectories();
            }
            catch {}

            if (rgdi != null)
                {
                foreach(DirectoryInfo di2 in rgdi)
                    {
                    long cBytesExcl2;

                    cBytes += GetDirSizeFromDirectoryInfo(sLabel + @"\" + di2.Name, di2, belExclusions, belInclusions, cLevel + 1, bep, iru, out cBytesExcl2);
                    cBytesExcl += cBytesExcl2;
                    }
                }

            // and now add on files -- this is where we actually check exclusions/inclusions....
            FileInfo []rgfi = null;

            try
            {
                rgfi = di.GetFiles();
            }
            catch {}

            if (rgfi != null)
                {
                foreach(FileInfo fi in rgfi)
                    {
                    try
                        {
                        string sFullName = fi.FullName;

                        if (bep.DoExclusions)
                            {
                            if ((belExclusions != null && belExclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or))
                                || (belInclusions != null && !belInclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or)))
                                {
                                if (bep.Verbose)
                                    iru.ReportFile(0, fi.Length, sLabel, sFullName);

                                cBytesExcl += fi.Length;
                                continue;
                                }
                            }

                        if (bep.Verbose)
                            iru.ReportFile(fi.Length, 0, sLabel, sFullName);

                        cBytes += fi.Length;
                        }
                    catch (Exception e)
                        {
                        Console.WriteLine(String.Format("cannot process file {0} in directory {1}: {2}", fi.Name, di.Name, e.Message));
                        }
                    }
                }

                iru.ReportDir(cBytes, cBytesExcl, sLabel, cLevel);

            iru.CloseDir();
            return cBytes;
        }