Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.47 KB | None | 0 0
  1. using Microsoft.Win32;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10.  
  11. namespace TextEditor
  12. {
  13.     /// <summary>
  14.     /// Interaction logic for MainWindow.xaml
  15.     /// </summary>
  16.     public partial class MainWindow : Window
  17.     {
  18.         public MainWindow()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.  
  24.         private async Task<StringBuilder[]> Limpar(string[] split)
  25.         {
  26.             var stringBuilder = new StringBuilder();
  27.  
  28.  
  29.             var task = Task.Factory.StartNew(() =>
  30.             {
  31.                 for (int x = 1; x < split.Length; x += 2)
  32.                 {
  33.                     stringBuilder.AppendLine($"{split[x]}");
  34.                 }
  35.                 return stringBuilder;
  36.             });
  37.  
  38.  
  39.             return await Task.WhenAll(task);
  40.         }
  41.  
  42.         private async Task<StringBuilder[]> Convert(string original, string[] limpo)
  43.         {
  44.             var stringBuilder = new StringBuilder();
  45.             var task = Task.Factory.StartNew(() =>
  46.             {
  47.                 string[] stringSeparators = new string[] { "\r\n" };
  48.                 string[] lines = original.Split(stringSeparators, StringSplitOptions.None);
  49.                 if (lines.Length == 1)
  50.                 {
  51.                     stringSeparators = new string[] { "\n" };
  52.                     lines = original.Split(stringSeparators, StringSplitOptions.None);
  53.                 }
  54.  
  55.                 string[] splitTemp;
  56.                 int count = 0;
  57.                 for (int x = 0; x < lines.Length; x++)
  58.                 {
  59.                     string line = lines[x];
  60.                     splitTemp = line.Split('"');
  61.                     for (int i = 1; i < splitTemp.Length; i += 2)
  62.                     {
  63.                         if (splitTemp[i] == "") continue;
  64.                         string toReplace = splitTemp[i];
  65.                         string replace = limpo[count];
  66.                         line = line.Replace(toReplace, replace);
  67.                         count++;
  68.                     }
  69.                     stringBuilder.AppendLine(line);
  70.                 }
  71.                 return stringBuilder;
  72.             });
  73.  
  74.             return await Task.WhenAll(task);
  75.         }
  76.  
  77.         private void Image_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  78.         {
  79.             btn1.Visibility = Visibility.Collapsed;
  80.         }
  81.  
  82.         private void Btn2_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  83.         {
  84.             btn1.Visibility = Visibility.Visible;
  85.         }
  86.  
  87.         private void BtnExportar_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
  88.         {
  89.             SaveFileDialog dialog = new SaveFileDialog()
  90.             {
  91.                 Filter = "Text Files(*.txt)|*.txt|All(*.*)|*"
  92.             };
  93.  
  94.             if (dialog.ShowDialog() == true)
  95.             {
  96.                 File.WriteAllText(dialog.FileName, txtFinal.Text, Encoding.GetEncoding(1252));
  97.             }
  98.         }
  99.  
  100.         private async void BtnImportar_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
  101.         {
  102.             OpenFileDialog openFileDialog = new OpenFileDialog();
  103.             openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  104.             if (openFileDialog.ShowDialog() == true)
  105.             {
  106.                 var teste = openFileDialog.FileName;
  107.  
  108.                 txtTextoOriginal.Clear();
  109.  
  110.                 txtTextoOriginal.Text = (File.ReadAllText(openFileDialog.FileName, Encoding.GetEncoding(1252)));
  111.             }
  112.  
  113.             var split = txtTextoOriginal.Text.Split('"');
  114.            
  115.             txtLimpo.Clear();
  116.  
  117.             var t = await Limpar(split);
  118.             txtLimpo.AppendText(t[0].ToString());
  119.         }
  120.  
  121.         private async void BtnVisualizar_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
  122.         {
  123.             txtFinal.Clear();
  124.  
  125.             var tScheduler = TaskScheduler.FromCurrentSynchronizationContext();
  126.  
  127.             string[] stringSeparators = new string[] { "\r\n" };
  128.  
  129.             string[] split = txtLimpo.Text.Split(stringSeparators, StringSplitOptions.None);
  130.  
  131.             split = split.Where(val => val != "").ToArray();
  132.  
  133.             var t = await Convert(txtTextoOriginal.Text, split);
  134.  
  135.             txtFinal.AppendText(t[0].ToString());
  136.         }
  137.  
  138.         private void Image_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  139.         {
  140.             Close();
  141.         }
  142.  
  143.         private void Image_MouseDown_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
  144.         {
  145.             SaveFileDialog dialog = new SaveFileDialog()
  146.             {
  147.                 Filter = "Text Files(*.txt)|*.txt|All(*.*)|*"
  148.             };
  149.  
  150.             if (dialog.ShowDialog() == true)
  151.             {
  152.                 File.WriteAllText(dialog.FileName, txtLimpo.Text, Encoding.GetEncoding(1252));
  153.             }
  154.         }
  155.  
  156.         private void Image_MouseDown_2(object sender, System.Windows.Input.MouseButtonEventArgs e)
  157.         {
  158.             MessageBox.Show("[Aviso]\n \rEsse Programa é Particular e não é permitido a venda, se você não comprou com o FROST, você esta sendo enganado.\n \rVocê pode denunciar o infrator e vamos beneficiar seu servidor com bons recursos exclusivos, veja nosso site.");
  159.             Process.Start("http://frost.4poring.com");
  160.         }
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement