Пример #1
0
 /// <summary>
 /// Loads a file into memory and prepares for compressing it to TLK
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="ff"></param>
 /// <param name="debugVersion"></param>
 public void LoadInputData(string fileName, TalkFile.Fileformat ff, bool debugVersion)
 {
     _inputData.Clear();
     LoadXmlInputData(fileName, debugVersion);
     _inputData.Sort();
     PrepareHuffmanCoding();
 }
Пример #2
0
        private void StartReadingTlkButton_Click(object sender, RoutedEventArgs e)
        {
            BusyReading(true);
            TalkFile.Fileformat ff = TalkFile.Fileformat.Xml;

            var loadingWorker = new BackgroundWorker();

            loadingWorker.WorkerReportsProgress = true;

            loadingWorker.ProgressChanged += delegate(object sender2, ProgressChangedEventArgs e2)
            {
                readingTlkProgressBar.Value = e2.ProgressPercentage;
            };

            loadingWorker.DoWork += delegate
            {
                try
                {
                    TalkFile tf = new TalkFile();
                    tf.LoadTlkData(_inputTlkFilePath);

                    tf.ProgressChanged += loadingWorker.ReportProgress;
                    tf.DumpToFile(_outputTextFilePath, ff);
                    // debug
                    // tf.PrintHuffmanTree();
                    tf.ProgressChanged -= loadingWorker.ReportProgress;
                }
                catch (FileNotFoundException)
                {
                    System.Windows.MessageBox.Show(
                        Properties.Resources.AlertExceptionTlkNotFound, Properties.Resources.Error,
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }
                catch (IOException)
                {
                    System.Windows.MessageBox.Show(
                        Properties.Resources.AlertExceptionTlkFormat, Properties.Resources.Error,
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }
                catch (Exception ex)
                {
                    string message = Properties.Resources.AlertExceptionGeneric;
                    message += Properties.Resources.AlertExceptionGenericDescription + ex.Message;
                    System.Windows.MessageBox.Show(message, Properties.Resources.Error,
                                                   MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            };

            loadingWorker.RunWorkerCompleted += delegate
            {
                BusyReading(false);
                System.Windows.MessageBox.Show(Properties.Resources.AlertTlkLoadingFinished, Properties.Resources.Done,
                                               MessageBoxButton.OK, MessageBoxImage.Information);
            };

            loadingWorker.RunWorkerAsync();
        }
Пример #3
0
        private void StartReadingTlkButton_Click(object sender, RoutedEventArgs e)
        {
            BusyReading(true);
            const TalkFile.Fileformat ff = TalkFile.Fileformat.Xml;

            var loadingWorker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            loadingWorker.ProgressChanged += delegate(object sender2, ProgressChangedEventArgs e2) { readingTlkProgressBar.Value = e2.ProgressPercentage; };

            loadingWorker.DoWork += delegate
            {
                //try
                //{
                var tf = new TalkFile();
                tf.LoadTlkData(InputTlkFilePath);

                tf.ProgressChanged += loadingWorker.ReportProgress;
                tf.DumpToFile(OutputTextFilePath, ff);
                // debug
                // tf.PrintHuffmanTree();
                tf.ProgressChanged -= loadingWorker.ReportProgress;

                /*}
                 * catch (FileNotFoundException)
                 * {
                 *      MessageBox.Show(Properties.Resources.AlertExceptionTlkNotFound, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                 * }
                 * catch (IOException)
                 * {
                 *      MessageBox.Show(Properties.Resources.AlertExceptionTlkFormat, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                 * }
                 * catch (Exception ex)
                 * {*/
                /*var message = Properties.Resources.AlertExceptionGeneric;
                 * message += Properties.Resources.AlertExceptionGenericDescription + ex.Message;*/
                //MessageBox.Show(ex.StackTrace, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                //}
            };

            loadingWorker.RunWorkerCompleted += delegate
            {
                BusyReading(false);
                MessageBox.Show(Properties.Resources.AlertTlkLoadingFinished, Properties.Resources.Done, MessageBoxButton.OK, MessageBoxImage.Information);
            };

            loadingWorker.RunWorkerAsync();
        }
Пример #4
0
        public void LoadInputData(string fileName, TalkFile.Fileformat ff, bool debugVersion)
        {
            _maleStrings.Clear();
            _femaleStrings.Clear();

            //_strings.Clear();
            LoadXmlInputData(fileName, debugVersion);

            _maleStrings.Sort((s1, s2) => (s1.Id & Int32.MaxValue).CompareTo(s2.Id & Int32.MaxValue));
            _femaleStrings.Sort((s1, s2) => (s1.Id & Int32.MaxValue).CompareTo(s2.Id & Int32.MaxValue));

            //var stringsList = _strings.OrderBy(pair => pair.Value.Position);

            PrepareHuffmanCoding();
        }