MiniME.Compiler.AddFiles C# (CSharp) Méthode

AddFiles() public méthode

public AddFiles ( string strFileName, System Encoding, bool Warnings ) : void
strFileName string
Encoding System
Warnings bool
Résultat void
        public void AddFiles(string strFileName, System.Text.Encoding Encoding, bool Warnings)
        {
            // Work out directory
            string strDirectory=System.IO.Path.GetDirectoryName(strFileName);
            string strFile=System.IO.Path.GetFileName(strFileName);
            if (String.IsNullOrEmpty(strDirectory))
            {
                strDirectory = System.IO.Directory.GetCurrentDirectory();
            }
            else
            {
                strDirectory = System.IO.Path.GetFullPath(strDirectory);
            }

            // Wildcard?
            if (strFile.Contains('*') || strFile.Contains('?'))
            {
                var files=System.IO.Directory.GetFiles(strDirectory, strFile, SearchOption.TopDirectoryOnly);
                foreach (var f in files)
                {
                    string strThisFile=System.IO.Path.Combine(strDirectory, f);

                    if ((from fx in m_files where string.Compare(fx.filename, strThisFile, true) == 0 select fx).Count() > 0)
                        continue;

                    AddFile(strThisFile, Encoding, Warnings);
                }
            }
            else
            {
                AddFile(System.IO.Path.Combine(strDirectory, strFile), Encoding, Warnings);
            }
        }

Same methods

Compiler::AddFiles ( string strFileName, bool Warnings ) : void

Usage Example

Exemple #1
0
        public bool ProcessArg(string a)
        {
            // Response file
            if (a.StartsWith("@"))
            {
                // Get the fully qualified response file name
                string strResponseFile = System.IO.Path.GetFullPath(a.Substring(1));

                // Load and parse the response file
                var args = Utils.ParseCommandLine(System.IO.File.ReadAllText(strResponseFile));

                // Set the current directory
                string OldCurrentDir = System.IO.Directory.GetCurrentDirectory();
                System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(strResponseFile));

                // Load the file
                bool bRetv = ProcessArgs(args);

                // Restore current directory
                System.IO.Directory.SetCurrentDirectory(OldCurrentDir);

                // Register the response file with the compiler so it can check it's time
                // stamp when using CheckFileTimes.
                m_compiler.RegisterResponseFile(strResponseFile);

                return(bRetv);
            }

            // Args are in format [/-]<switchname>[:<value>];
            if (a.StartsWith("/") || a.StartsWith("-"))
            {
                string SwitchName = a.Substring(1);
                string Value      = null;

                int colonpos = SwitchName.IndexOf(':');
                if (colonpos >= 0)
                {
                    // Split it
                    Value      = SwitchName.Substring(colonpos + 1);
                    SwitchName = SwitchName.Substring(0, colonpos);
                }

                switch (SwitchName)
                {
                case "h":
                case "?":
                    ShowLogo();
                    ShowHelp();
                    return(false);

                case "v":
                    ShowLogo();
                    return(false);

                case "nologo":
                    NoLogo = true;
                    break;

                case "o":
                    m_compiler.OutputFileName = System.IO.Path.GetFullPath(Value);
                    break;

                case "d":
                    System.IO.Directory.SetCurrentDirectory(Value);
                    break;

                case "stdout":
                    m_compiler.StdOut = true;
                    break;

                case "js":
                    m_compiler.MinifyKind = MinifyKind.JS;
                    break;

                case "css":
                    m_compiler.MinifyKind = MinifyKind.CSS;
                    break;

                case "linelen":
                    if (Value == null)
                    {
                        throw new Error("No value specified for argument `linelen`");
                    }
                    else
                    {
                        int linelen;
                        if (int.TryParse(Value, out linelen) && linelen >= 0)
                        {
                            m_compiler.MaxLineLength = linelen;
                        }
                        else
                        {
                            throw new Error("Invalid value specified for argument `linelen`");
                        }
                    }
                    break;

                case "inputencoding":
                    if (String.IsNullOrEmpty(Value) || Value == "auto")
                    {
                        m_useEncoding = null;
                    }
                    else
                    {
                        m_useEncoding = null;
                        try
                        {
                            m_useEncoding = MiniME.TextFileUtils.EncodingFromName(Value);
                        }
                        catch (Exception)
                        {
                            // Ignore
                        }
                        if (m_useEncoding == null)
                        {
                            throw new Error(string.Format("Unknown input encoding: `{0}`. Use -listencodings for a list", Value));
                        }
                    }
                    break;

                case "outputencoding":
                {
                    m_compiler.OutputEncoding = MiniME.TextFileUtils.EncodingFromName(Value);
                    if (m_compiler.OutputEncoding == null)
                    {
                        throw new Error(string.Format("Unknown output encoding: `{0}`. Use -listencodings for a list", Value));
                    }
                    break;
                }

                case "listencodings":
                {
                    foreach (var e in from x in System.Text.Encoding.GetEncodings() orderby x.Name select x)
                    {
                        Console.WriteLine("`{0}` - {1}", e.Name, e.DisplayName);
                    }
                    return(false);
                }


                case "no-obfuscate":
                    m_compiler.NoObfuscate = true;
                    break;

                case "ive-donated":
                    m_compiler.NoCredit = true;
                    break;

                case "check-filetimes":
                    m_compiler.CheckFileTimes = true;
                    break;

                case "no-options-file":
                    m_compiler.UseOptionsFile = false;
                    break;

                case "no-warnings":
                    m_warnings = false;
                    break;

                case "warnings":
                    m_warnings = true;
                    break;

                case "diag-formatted":
                    m_compiler.Formatted = true;
                    break;

                case "diag-symbols":
                    m_compiler.SymbolInfo = true;
                    m_compiler.Formatted  = true;
                    break;

                case "diag-ast":
                    m_compiler.DumpAST = true;
                    break;

                case "diag-scopes":
                    m_compiler.DumpScopes = true;
                    break;

                default:
                    throw new Error(string.Format("Unknown switch `{0}`", a));
                }
            }
            else
            {
                m_compiler.AddFiles(a, m_useEncoding, m_warnings);
            }

            return(true);
        }