Exemple #1
0
        public string ReadNWNLogAndInvokeParser(Settings _run_settings)
        {
            string   result;
            DateTime _dateTime         = CurrentDateTime_Get();
            string   filepath          = FilePath_Get(_run_settings);
            string   filename          = FileNameGenerator_Get(_dateTime);
            bool     ActorThresholdMet = true;


            FileStream fs;

            try
            {
                fs = new FileStream(_run_settings.PathToLog, FileMode.Open);
            }
            catch
            {
                MessageBox.Show("NWNLogRotator could not read the Log at PathToLog specified!",
                                "Invalid Log Location",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return("");
            }

            LogParser instance = new LogParser();

            result = instance.ParseLog(fs, _run_settings.CombatText, _run_settings.EventText, _run_settings.ServerName, _run_settings.ServerNameColor);
            fs.Close();

            // maintain minimum row lines requirement
            ActorThresholdMet = instance.ActorOccurences_Get(result, _run_settings.MinimumRowsCount);
            if (ActorThresholdMet == false)
            {
                MessageBox.Show("This NWN Log did not meet the 'Minimum Rows' requirement. The specified log file was not saved!",
                                "Minimum Rows Information",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
                return("");
            }


            try
            {
                File.WriteAllText(filepath + filename, result);
                return(filepath + filename);
            }
            catch
            {
                MessageBoxResult _messageBoxResult = MessageBox.Show("The destination file " + filepath + filename + " is unable to be written to this folder. Would you like NNWNLogRotator to try and create the destination folder?",
                                                                     "Output Directory Invalid",
                                                                     MessageBoxButton.YesNo,
                                                                     MessageBoxImage.Question);
                if (_messageBoxResult == MessageBoxResult.Yes)
                {
                    // create folder
                    if (!Directory.Exists(filepath))
                    {
                        try
                        {
                            Directory.CreateDirectory(filepath);
                        }
                        catch
                        {
                            MessageBox.Show("NWNLogRotator was not able create a folder or verify the folder structure of the Output Directory.",
                                            "Invalid Output Directory",
                                            MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                            return("");
                        }
                        try
                        {
                            File.WriteAllText(filepath + filename, result);
                            return(filepath + filename);
                        }
                        catch
                        {
                            MessageBox.Show("NWNLogRotator was not able to write to the entered Output Directory. Please ensure the file structure exists.",
                                            "Output Directory Error",
                                            MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                    }
                }
            }
            return("");
        }