Ejemplo n.º 1
0
        static String strOutDir; // Output directory

        #endregion Fields

        #region Methods

        // =================== Local variables ===============================================
        // Command-line entry point + argument handling
        static void Main(string[] args)
        {
            String sInput = "";       // Input file or dir
              String sOutput = "";      // Output directory
              String sDict = "";        // Movie dictionary
              bool bIsDebug = false;    // Debugging
              bool bForce = false;      // Force
              bool bMulti = false;      // Only do multi-part subtitles

              try {
            // Check command-line options
            for (int i = 0; i < args.Length; i++) {
              // get this argument
              String sArg = args[i];
              if (sArg.StartsWith("-")) {
            // Check out the arguments
            switch (sArg.Substring(1)) {
              case "i": // Input file or directory with .folia.xml files
                sInput = args[++i];
                break;
              case "o": // Output directory
                sOutput = args[++i];
                break;
              case "m": // Movie dictionary   -- Tab-separated list from opensubtitles.org
                sDict = args[++i];
                break;
              case "2":
                bMulti = true;
                break;
              case "f": // Force
                bForce = true;
                break;
              case "d": // Debugging
                bIsDebug = true;
                break;
            }
              } else {
            // Throw syntax error and leave
            SyntaxError("1 - i=" + i + " args=" + args.Length + " argCurrent=[" + sArg + "]"); return;
              }
            }
            // Check presence of input/output
            if (sInput == "" || sOutput == "") { SyntaxError("2"); return; }
            // Check existence of output dir
            if (!Directory.Exists(sOutput)) {
              // Create the output directory
              Directory.CreateDirectory(sOutput);
            }
            // Initialize the main entry point for the conversion
            opsConv objConv = new opsConv();

            // Load the movie dictionary
            if (!objConv.loadMovieDictionary(sDict)) {
              errHandle.DoError("Main", "Could not load movie dictionary from [" + sDict + "]");
              return;
            }

            // Initialise the Treebank Xpath functions, which may make use of tb:matches()
            util.XPathFunctions.conTb.AddNamespace("tb", util.XPathFunctions.TREEBANK_EXTENSIONS);

            // Check if the input is a directory or file
            if (Directory.Exists(sInput)) {
              // Filter: make sure we only pass on the *first* of multiple files
              //        (Handler needs to process the additional ones)
              WalkDirectoryTree(sInput, "*_1of*.gz", sInput, sOutput, bForce, bMulti, bIsDebug, ref objConv);
            } else {
              // Show we don't have input file
              errHandle.DoError("Main", "Cannot find input file(s) in: " + sInput);
            }
            // Exit the program
            Console.WriteLine("Ready");
              } catch (Exception ex) {
            errHandle.DoError("Main", ex); // Provide standard error message
            throw;
              }
        }
Ejemplo n.º 2
0
        static String strOutDir; // Output directory
        // =================== Local variables ===============================================
        // Command-line entry point + argument handling
        static void Main(string[] args)
        {
            String sInput   = "";    // Input file or dir
            String sOutput  = "";    // Output directory
            String sDict    = "";    // Movie dictionary
            bool   bIsDebug = false; // Debugging
            bool   bForce   = false; // Force
            bool   bMulti   = false; // Only do multi-part subtitles

            try {
                // Check command-line options
                for (int i = 0; i < args.Length; i++)
                {
                    // get this argument
                    String sArg = args[i];
                    if (sArg.StartsWith("-"))
                    {
                        // Check out the arguments
                        switch (sArg.Substring(1))
                        {
                        case "i": // Input file or directory with .folia.xml files
                            sInput = args[++i];
                            break;

                        case "o": // Output directory
                            sOutput = args[++i];
                            break;

                        case "m": // Movie dictionary   -- Tab-separated list from opensubtitles.org
                            sDict = args[++i];
                            break;

                        case "2":
                            bMulti = true;
                            break;

                        case "f": // Force
                            bForce = true;
                            break;

                        case "d": // Debugging
                            bIsDebug = true;
                            break;
                        }
                    }
                    else
                    {
                        // Throw syntax error and leave
                        SyntaxError("1 - i=" + i + " args=" + args.Length + " argCurrent=[" + sArg + "]"); return;
                    }
                }
                // Check presence of input/output
                if (sInput == "" || sOutput == "")
                {
                    SyntaxError("2"); return;
                }
                // Check existence of output dir
                if (!Directory.Exists(sOutput))
                {
                    // Create the output directory
                    Directory.CreateDirectory(sOutput);
                }
                // Initialize the main entry point for the conversion
                opsConv objConv = new opsConv();

                // Load the movie dictionary
                if (!objConv.loadMovieDictionary(sDict))
                {
                    errHandle.DoError("Main", "Could not load movie dictionary from [" + sDict + "]");
                    return;
                }

                // Initialise the Treebank Xpath functions, which may make use of tb:matches()
                util.XPathFunctions.conTb.AddNamespace("tb", util.XPathFunctions.TREEBANK_EXTENSIONS);

                // Check if the input is a directory or file
                if (Directory.Exists(sInput))
                {
                    // Filter: make sure we only pass on the *first* of multiple files
                    //        (Handler needs to process the additional ones)
                    WalkDirectoryTree(sInput, "*_1of*.gz", sInput, sOutput, bForce, bMulti, bIsDebug, ref objConv);
                }
                else
                {
                    // Show we don't have input file
                    errHandle.DoError("Main", "Cannot find input file(s) in: " + sInput);
                }
                // Exit the program
                Console.WriteLine("Ready");
            } catch (Exception ex) {
                errHandle.DoError("Main", ex); // Provide standard error message
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// WalkDirectoryTree --
        ///     Recursively walk the directory starting with @sStartDir
        ///     Execute conversion on any .gz file encountered using @objConv
        /// </summary>
        /// <param name="sStartDir"></param>
        /// <param name="sFilter"></param>
        /// <param name="sInput"></param>
        /// <param name="sOutput"></param>
        /// <param name="bForce"></param>
        /// <param name="bIsDebug"></param>
        /// <param name="objConv"></param>
        static void WalkDirectoryTree(String sStartDir, String sFilter, String sInput, 
      String sOutput, bool bForce, bool bMulti, bool bIsDebug, ref opsConv objConv)
        {
            String[] arFiles = null;
              String[] arSubDirs = null;

              // Exclude 'raw'
              if (sStartDir.Contains("/raw/") || sStartDir.Contains("\\raw\\")) return;
              // First, process all the files directly under this folder
              try {
            arFiles = Directory.GetFiles(sStartDir, sFilter);
              }
              // This is thrown if even one of the files requires permissions greater
              // than the application provides.
              catch (UnauthorizedAccessException e) {
            // Only give warning
            errHandle.Status(e.Message);
              } catch (System.IO.DirectoryNotFoundException e) {
            errHandle.Status(e.Message);
              }

              // Check if all is valid
              if (arFiles != null) {
            // Walk all files in this directory
            foreach (String sFile in arFiles) {
              // Parse this input file to the output directory
              if (!objConv.ConvertOneOpsToFolia(sFile, sInput, sOutput, bForce, bMulti, bIsDebug)) {
            errHandle.DoError("Main", "Could not convert file [" + sFile + "]");
            return;
              }
            }

            // Now find all the subdirectories under this directory.
            arSubDirs = Directory.GetDirectories(sStartDir);
            // Walk all directories
            foreach (String sDirName in arSubDirs) {
              // Resursive call for each subdirectory.
              WalkDirectoryTree(sDirName, sFilter, sInput, sOutput, bForce, bMulti, bIsDebug, ref objConv);
            }

              }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// WalkDirectoryTree --
        ///     Recursively walk the directory starting with @sStartDir
        ///     Execute conversion on any .gz file encountered using @objConv
        /// </summary>
        /// <param name="sStartDir"></param>
        /// <param name="sFilter"></param>
        /// <param name="sInput"></param>
        /// <param name="sOutput"></param>
        /// <param name="bForce"></param>
        /// <param name="bIsDebug"></param>
        /// <param name="objConv"></param>
        static void WalkDirectoryTree(String sStartDir, String sFilter, String sInput,
                                      String sOutput, bool bForce, bool bMulti, bool bIsDebug, ref opsConv objConv)
        {
            String[] arFiles   = null;
            String[] arSubDirs = null;

            // Exclude 'raw'
            if (sStartDir.Contains("/raw/") || sStartDir.Contains("\\raw\\"))
            {
                return;
            }
            // First, process all the files directly under this folder
            try {
                arFiles = Directory.GetFiles(sStartDir, sFilter);
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e) {
                // Only give warning
                errHandle.Status(e.Message);
            } catch (System.IO.DirectoryNotFoundException e) {
                errHandle.Status(e.Message);
            }

            // Check if all is valid
            if (arFiles != null)
            {
                // Walk all files in this directory
                foreach (String sFile in arFiles)
                {
                    // Parse this input file to the output directory
                    if (!objConv.ConvertOneOpsToFolia(sFile, sInput, sOutput, bForce, bMulti, bIsDebug))
                    {
                        errHandle.DoError("Main", "Could not convert file [" + sFile + "]");
                        return;
                    }
                }

                // Now find all the subdirectories under this directory.
                arSubDirs = Directory.GetDirectories(sStartDir);
                // Walk all directories
                foreach (String sDirName in arSubDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(sDirName, sFilter, sInput, sOutput, bForce, bMulti, bIsDebug, ref objConv);
                }
            }
        }