Exemplo n.º 1
0
        private void soundProcessing(object dataObject)
        {
            var data = (ProcessingThreadData)dataObject;

            // Wait while files are in use.
            while (FilesHelper.FileIsInUse(data.TempInFileName) || FilesHelper.FileIsInUse(data.TempOutFileName))
            {
            }

            var joinedFileName = joinSoundChannels(data.TempInFileName, data.TempOutFileName);

            if (joinedFileName == null)
            {
                return;
            }

            File.Delete(data.TempInFileName);
            File.Delete(data.TempOutFileName);

            // Encode merged file to MP3.
            var duration       = DateTime.Now - data.StartRecordDateTime;
            var recordFileName = Settings.RenderFileName(
                data.RecordRawFileName, data.CallerName, data.StartRecordDateTime, duration);

            if (!DirectoriesHelper.CreateDirectory(recordFileName) || !encodeMp3(joinedFileName, recordFileName))
            {
                // Encode to settings folder with default file name if unable encode to the desired file name.
                recordFileName = Path.Combine(Settings.SettingsFolder, Settings.RenderFileName(
                                                  Settings.DEFAULT_FILE_NAME, data.CallerName, data.StartRecordDateTime, duration));

                if (!encodeMp3(joinedFileName, recordFileName))
                {
                    // If encoding fails anyway then return WAV file to user.
                    recordFileName = Path.ChangeExtension(recordFileName, "wav");
                    File.Copy(joinedFileName, recordFileName, true);
                }

                // Report about error and ask about opening folder with resulting file.
                if (MessageBox.Show(string.Format(RECORD_SAVE_ERROR, data.RecordRawFileName, recordFileName),
                                    "Saving error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                {
                    Process.Start(Settings.SettingsFolder);
                }
            }

            updateLastRecordFileName(recordFileName);
            File.Delete(joinedFileName);
        }
Exemplo n.º 2
0
        private static void PrepareEnvironment(UserSettings userSettings)
        {
            try
            {
                if (!FilesHelper.FileExists(userSettings.TasksLocation))
                {
                    FilesHelper.OpenOrCreateFile(userSettings.TasksLocation);
                }
                if (!FilesHelper.FileExists(userSettings.SettingsFileLocation))
                {
                    FilesHelper.OpenOrCreateFile(userSettings.SettingsFileLocation);
                    FilesHelper.WriteAllText(userSettings.SettingsFileLocation, JsonHelper.Serialize(userSettings));
                }

                if (!DirectoriesHelper.DirectoryExists(userSettings.DownloadLocation))
                {
                    DirectoriesHelper.CreateDirectory(userSettings.DownloadLocation);
                }
            }
            catch
            {
                NotificationsHelper.DisplayMessage(Messages.ErrorInitiatingConfiguration);
            }
        }