Exemplo n.º 1
0
        /// <summary>
        /// Initial program entry point.
        /// </summary>
        /// <param name="args">The args.</param>
        public static void Main(string[] args)
        {
            THelper.AddTextLogger("CLAutoThumbnailer.log", "mainlogger");

            CLAutoThumbnailer thumbnailer = null;
            try
                {
                thumbnailer = new CLAutoThumbnailer (args, null);
                }
            catch (NDesk.Options.OptionException e)
                {
                THelper.Critical ("CLAutoThumbnailer: ");
                THelper.Critical (e.Message);
                THelper.Critical ("Try `CLAutoThumbnailer --help' for more information.");
                return;
                }

            if (thumbnailer._debug == DebugModes.ShowDebuggingMessages)
                THelper.SetConsoleLevel (System.Diagnostics.SourceLevels.Verbose);

            if (thumbnailer._videoExtsChanged)
                thumbnailer.InitializeVideoRE ();

            if (thumbnailer._show_help)
                {
                ShowHelp (thumbnailer._oset);
                return;
                }

            if (thumbnailer._show_version)
                {
                string version = System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
                Console.WriteLine ("CLAutoThumbnailer v{0}", version);
                return;
                }

            if (thumbnailer._dumpCRs)
                {
                thumbnailer.DumpColRowsPlot (thumbnailer._dumpFilename,
                                             thumbnailer._dumpThresholds);
                return;
                }

            if (thumbnailer._saveSettings)
                {
                thumbnailer.SaveThumbnailSettings ();
                Console.WriteLine ("Current settings saved as default.");
                }

            if (thumbnailer._resetSettings)
                {
                Properties.Settings.Default.Reset ();
                thumbnailer.InitializeThumbnailSettings ();
                thumbnailer.SaveThumbnailSettings ();
                Console.WriteLine ("Settings reset to application defaults.");
                return;
                }

            if (thumbnailer._fileList == null &&
                thumbnailer._directoryArg == null &&
                thumbnailer._cmdDirectory == null)
                {
                Console.WriteLine ("No filename or directory specified.");
                Console.WriteLine ("Try `CLAutoThumbnailer --help' for more information.");
                //ShowHelp (thumbnailer._oset);
                return;
                }

            if ((thumbnailer._outputDirectory != null) &&
                !System.IO.Directory.Exists (thumbnailer._outputDirectory))
                {
                Console.WriteLine ("\"" + thumbnailer._outputDirectory + "\" doesn't exist.");
                thumbnailer._outputDirectory = null;
                return;
                }

            DateTime startTime = DateTime.Now;
            string cmdline = System.Environment.CommandLine.Split(
                                    new Char[] {' '}, 2)[1];
            THelper.Debug ("Command Line: {0}", cmdline);
            THelper.Information ("{0}", startTime);

            if (thumbnailer._cmdDirectory != null)
                {
                string directory = System.IO.Path.GetFullPath (thumbnailer._cmdDirectory);

                string commandFilename = "CLAutotn-temp.txt";
                if (thumbnailer._filename != null)
                    {
                    if (System.IO.Path.GetExtension (thumbnailer._filename).ToLower () == ".txt")
                        commandFilename = thumbnailer._filename;
                    }
                commandFilename = System.IO.Path.GetFullPath (commandFilename);
                string baseDir = System.IO.Path.GetDirectoryName (commandFilename);

                using (System.IO.StreamWriter sw = new System.IO.StreamWriter (commandFilename))
                    thumbnailer.GenerateCommandFile (sw, directory, baseDir);
                THelper.Information ("Command File '{0}' created.", commandFilename);
                }
            else
                {
                if (thumbnailer._filename != null)
                    {
                    if (System.IO.Path.GetExtension (thumbnailer._filename).ToLower () != ".txt")
                        {
                        thumbnailer.ProcessFiles (thumbnailer._fileList,
                                                  thumbnailer._displayFilename,
                                                  thumbnailer._outputDirectory);
                        }
                    else
                        thumbnailer.ProcessCommandFile (thumbnailer._filename);
                    }
                }

            if (thumbnailer._directoryArg != null)
                {
                string directory = System.IO.Path.GetFullPath (thumbnailer._directoryArg);

                // Don't log progress messages if '-d .' was specified on command line
                //  since Main() has already created a logger for the working directory.
                thumbnailer.ProcessDirectory (directory, cmdline, thumbnailer._directoryArg==".");
                }

            DateTime endTime = DateTime.Now;
            THelper.Information ("{0} Total time.", (endTime - startTime).ToString (@"h\:mm\:ss"));
            THelper.Information ("{0}", endTime);
            THelper.Information ();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes a command file (typically generated by <see cref="GenerateCommandFile"/>
        /// and then manually edited).
        /// </summary>
        /// <param name="filename">The filename of the command file to process.</param>
        private void ProcessCommandFile(string filename)
        {
            string baseDir =
                System.IO.Path.GetDirectoryName (System.IO.Path.GetFullPath(filename));

            using (System.IO.StreamReader sr = System.IO.File.OpenText (filename))
                {
                String input;

                THelper.Information ("Processing command file: {0}", filename);

                while ((input = sr.ReadLine ()) != null)
                    {
                    input = input.Trim ();
                    if (input.Length <= 0)
                        continue;
                    if (input.StartsWith ("#"))
                        continue;
                    string[] args = GetArgs(input);

                    CLAutoThumbnailer cftn = null;
                    try
                        {
                        cftn = new CLAutoThumbnailer (args, baseDir);
                        }
                    catch (NDesk.Options.OptionException e)
                        {
                        THelper.Critical ("CLAutoThumbnailer: ");
                        THelper.Critical (e.Message);
                        continue;
                        }

                    cftn._debug = _debug;

                    if (_tnSettings.ScaleFactor != 1.0)
                        cftn._tnSettings.ScaleFactor = _tnSettings.ScaleFactor;

                    if (cftn._show_help)
                        continue;

                    if (cftn._filename == null && cftn._directoryArg == null)
                        {
                        THelper.Critical ("No filename or directory specified: {0}", input);
                        continue;
                        }

                    if ((cftn._outputDirectory != null) &&
                        !System.IO.Directory.Exists (cftn._outputDirectory))
                        {
                        THelper.Critical ("\"" + cftn._outputDirectory + "\" doesn't exist.");
                        continue;
                        }
                    if (cftn._outputDirectory == null && _outputDirectory != null)
                        cftn._outputDirectory = _outputDirectory;
                    if (cftn._tnSettings.SubDirectory == "" && _tnSettings.SubDirectory != "")
                        cftn._tnSettings.SubDirectory = _tnSettings.SubDirectory;

                    string logFile;

                    if (cftn._filename != null)
                        {
                        if (System.IO.Path.GetExtension(cftn._filename).ToLower() == ".txt")
                            {
                            THelper.Critical ("Command File \"" + cftn._filename +
                                              "\" can't be used inside another Command File.");
                            continue;
                            }

                        string path = System.IO.Path.GetDirectoryName (
                            System.IO.Path.GetFullPath (cftn._filename));
                        logFile = System.IO.Path.Combine (path, "CLAutoThumbnailer.log");

                        List<string> files = CreateFileList (cftn._filename);
                        if (files == null)
                            {
                            THelper.Critical ("\"" + cftn._filename + "\" doesn't exist.");
                            }
                        else if (files.Count == 0)
                            {
                            THelper.Critical ("\"" + cftn._filename +
                                              "\" doesn't match any files.");
                            }
                        else
                            {
                            THelper.AddTextLogger (logFile, path);
                            THelper.Debug ("Command Line: {0}", input);

                            cftn.ProcessFiles (files, cftn._displayFilename,
                                                      cftn._outputDirectory);

                            THelper.RemoveTextLogger (path);
                            }

                        }

                    if (cftn._directoryArg != null)
                        {
                        string directory = System.IO.Path.GetFullPath (cftn._directoryArg);

                        // Don't log progress messages if '-d .' was specified on command line
                        //  since Main() has already created a logger for the working directory.
                        cftn.ProcessDirectory (directory, input,
                                                      cftn._directoryArg == ".");
                        }
                    }
                }
        }