当前位置: 首页>>代码示例>>C#>>正文


C# UTF8Encoding.CopyTo方法代码示例

本文整理汇总了C#中System.Text.UTF8Encoding.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.CopyTo方法的具体用法?C# UTF8Encoding.CopyTo怎么用?C# UTF8Encoding.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UTF8Encoding的用法示例。


在下文中一共展示了UTF8Encoding.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetFile

        void SetFile(string path)
        {
            try
            {
                ValidateInputFile(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (inputFile != null)
                inputFile.Close();
            UnloadFonts();

            textBoxIn.Text = path;
            string fullPath = Path.GetDirectoryName(path);
            string name = Path.GetFileNameWithoutExtension(path);
            string title = name;
            if (textBoxOut.Text == _autoOutput || textBoxOut.Text == "")
                textBoxOut.Text = _autoOutput = Path.Combine(string.IsNullOrWhiteSpace(Properties.Settings.Default.RememberedFolderOut) ? fullPath : Properties.Settings.Default.RememberedFolderOut, name + ".webm");
            audioDisabled = false;

            progressBarIndexing.Style = ProgressBarStyle.Marquee;
            progressBarIndexing.Value = 30;
            boxIndexingProgress.Text = "";
            panelHideTheOptions.BringToFront();

            buttonGo.Enabled = false;
            buttonPreview.Enabled = false;
            buttonBrowseIn.Enabled = false;
            textBoxIn.Enabled = false;

            inputFile = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);

            // Reset filters
            Filters.ResetFilters();
            DefaultSettings();
            listViewProcessingScript.Clear();
            boxAdvancedScripting.Checked = false; // STUB: this part is weak
            boxAdvancedScripting.Enabled = true;
            textBoxProcessingScript.Hide();
            listViewProcessingScript.Show();

            if (Path.GetExtension(path) == ".avs")
            {
                Program.InputFile = path;
                Program.InputType = FileType.Avisynth;

                BackgroundWorker probebw = new BackgroundWorker();
                probebw.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    ProbeScript();
                };
                probebw.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    boxAdvancedScripting.Enabled = false;
                    listViewProcessingScript.Enabled = false;
                    showToolTip("You're loading an AviSynth script, so Processing is disabled!", 3000);

                    comboLevels.Enabled = boxDeinterlace.Enabled = boxDenoise.Enabled = false;
                    buttonGo.Enabled = buttonBrowseIn.Enabled = textBoxIn.Enabled = true;
                    toolStripFilterButtonsEnabled(false);
                    panelHideTheOptions.SendToBack();
                };

                labelIndexingProgress.Text = "Probing script...";
                probebw.RunWorkerAsync();
                return;
            }
            else
            {
                Program.InputFile = path;
                Program.InputType = FileType.Video;
                Program.FileMd5 = null;
                listViewProcessingScript.Enabled = true;
                comboLevels.Enabled = boxDeinterlace.Enabled = boxDenoise.Enabled = true;
            }

            GenerateAvisynthScript();

            // Hash some of the file to make sure we didn't index it already
            labelIndexingProgress.Text = "Hashing...";
            logIndexingProgress("Hashing...");
            using (MD5 md5 = MD5.Create())
            using (FileStream stream = File.OpenRead(path))
            {
                var filename = new UTF8Encoding().GetBytes(name);
                var buffer = new byte[4096];

                filename.CopyTo(buffer, 0);
                stream.Read(buffer, filename.Length, 4096 - filename.Length);

                Program.FileMd5 = BitConverter.ToString(md5.ComputeHash(buffer));
                logIndexingProgress("File hash is " + Program.FileMd5.Replace("-", ""));
                _indexFile = Path.Combine(Path.GetTempPath(), Program.FileMd5 + ".ffindex");
            }

            FFMSSharp.Index index = null;
//.........这里部分代码省略.........
开发者ID:rweichler,项目名称:WebMConverter,代码行数:101,代码来源:MainForm.cs

示例2: buttonConfirm_Click

        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            var audioFile = boxAudioFile.Text;
            string indexFile;

            try
            {
                if (!File.Exists(audioFile))
                    throw new FileNotFoundException();

                panelIndexingProgress.BringToFront();
                labelIndexingProgress.Text = "Hashing...";

                using (var md5 = MD5.Create())
                using (var stream = File.OpenRead(audioFile))
                {
                    var filename = new UTF8Encoding().GetBytes(Path.GetFileNameWithoutExtension(audioFile));
                    var buffer = new byte[4096];

                    filename.CopyTo(buffer, 0);
                    stream.Read(buffer, filename.Length, 4096 - filename.Length);

                    var hash = BitConverter.ToString(md5.ComputeHash(buffer));
                    indexFile = Path.Combine(Path.GetTempPath(), hash + ".ffindex");
                }

                if (File.Exists(indexFile))
                {
                    try
                    {
                        var index = new Index(indexFile);

                        if (index.BelongsToFile(audioFile))
                        {
                            DialogResult = DialogResult.OK;
                            GeneratedFilter = new DubFilter(audioFile, indexFile, (DubMode)comboDubMode.SelectedIndex);
                            Close();
                            return;
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    File.Delete(indexFile);
                }

                labelIndexingProgress.Text = "Indexing...";
                progressIndexingProgress.Value = 0;
                progressIndexingProgress.Style = ProgressBarStyle.Continuous;
                _worker = new BackgroundWorker
                {
                    WorkerSupportsCancellation = true,
                    WorkerReportsProgress = true
                };
                _worker.ProgressChanged += (o, args) =>
                {
                    progressIndexingProgress.Value = args.ProgressPercentage;
                };
                _worker.DoWork += (bw, workArgs) =>
                {
                    var indexer = new Indexer(audioFile, Source.Lavf);

                    indexer.UpdateIndexProgress += (ind, updateArgs) =>
                    {
                        _worker.ReportProgress((int) (((double) updateArgs.Current/updateArgs.Total)*100));
                        indexer.CancelIndexing = _worker.CancellationPending;
                    };

                    try
                    {
                        var index = indexer.Index();

                        try
                        {
                            index.GetFirstIndexedTrackOfType(TrackType.Audio);
                        }
                        catch (KeyNotFoundException)
                        {
                            throw new InvalidDataException("That file doesn't have any audio!");
                        }

                        index.WriteIndex(indexFile);

                    }
                    catch (OperationCanceledException)
                    {
                        workArgs.Cancel = true;
                    }
                };
                _worker.RunWorkerCompleted += (o, args) =>
                {
                    this.InvokeIfRequired(() =>
                    {
                        panelIndexingProgress.SendToBack();
                    });

                    if (args.Error != null)
                    {
//.........这里部分代码省略.........
开发者ID:rweichler,项目名称:WebMConverter,代码行数:101,代码来源:Dub.cs


注:本文中的System.Text.UTF8Encoding.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。