163 lines
4.5 KiB
C#
163 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Xylem.Common.Ui.GenesisToolBox
|
|
{
|
|
public partial class FrmLogSplit : Form
|
|
{
|
|
private List<TextFileMatchControl> FileMatchControls = new List<TextFileMatchControl>();
|
|
public FrmLogSplit()
|
|
{
|
|
InitializeComponent();
|
|
|
|
for (Int32 i = 0; i < 4; i++)
|
|
{
|
|
var a = new TextFileMatchControl(i);
|
|
|
|
a.Location = new System.Drawing.Point(10, (i * a.Height) + 15);
|
|
|
|
FileMatchControls.Add(a);
|
|
}
|
|
foreach (var item in FileMatchControls)
|
|
{
|
|
groupBox1.Controls.Add(item);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void FrmLogSplit_Load(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnOpenUpdateDirectory_Click(Object sender, EventArgs e)
|
|
{
|
|
if (openFileDialog.ShowDialog() != DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
|
|
tbxFilePathSource.Text = openFileDialog.FileName;
|
|
|
|
tbxFilePathDestMisc.Text = $"{tbxFilePathSource.Text}_NoMatch";
|
|
|
|
tbxFilePathCorrupted.Text = $"{tbxFilePathSource.Text}_Corrupted";
|
|
|
|
|
|
foreach (var item in FileMatchControls)
|
|
{
|
|
item.SetMainFile(tbxFilePathSource.Text);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void btnOpenUpdateDirectoryCorrupted_Click(Object sender, EventArgs e)
|
|
{
|
|
if (openFileDialog.ShowDialog() != DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
|
|
tbxFilePathCorrupted.Text = openFileDialog.FileName;
|
|
|
|
tbxFilePathCorrupted.Text = $"{tbxFilePathSource.Text}";
|
|
|
|
foreach (var item in FileMatchControls)
|
|
{
|
|
item.SetMainFile(tbxFilePathSource.Text);
|
|
}
|
|
}
|
|
|
|
|
|
private void btnOpenUpdateDirectoryRest_Click(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnRun_Click(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
|
|
var regexMatch = tbxRegExMatch.Text;
|
|
var serachDic = new Dictionary<String, TextFileMatchControl>();
|
|
|
|
foreach (var item in FileMatchControls)
|
|
{
|
|
item.PrepareRun();
|
|
if (item.IsValid())
|
|
{
|
|
serachDic.Add(item.Matching(), item);
|
|
}
|
|
|
|
//item.SetMainFile(tbxFilePathSource.Text);
|
|
}
|
|
|
|
var lines = File.ReadAllLines(tbxFilePathSource.Text).ToList();
|
|
|
|
var sbNoMatch = new StringBuilder();
|
|
var sbCorrupted = new StringBuilder();
|
|
foreach (var line in lines)
|
|
{
|
|
var match = false;
|
|
var matchingStr = line.Replace(" ", "");
|
|
matchingStr = matchingStr.Replace("@h", "");
|
|
matchingStr = matchingStr.Replace("@f", "");
|
|
matchingStr = matchingStr.Replace("-", "");
|
|
matchingStr = matchingStr.Replace(":", "");
|
|
if (System.Text.RegularExpressions.Regex.IsMatch(matchingStr, @"^[0-9A-F]+$"))
|
|
{
|
|
|
|
foreach (var item in serachDic)
|
|
{
|
|
if (line.Contains(item.Key))
|
|
{
|
|
if (item.Value.AddText(line))
|
|
{
|
|
match = true;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
if (!match)
|
|
{
|
|
sbNoMatch.AppendLine(line);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sbCorrupted.AppendLine(line);
|
|
}
|
|
}
|
|
File.WriteAllText(tbxFilePathDestMisc.Text, sbNoMatch.ToString());
|
|
File.WriteAllText(tbxFilePathCorrupted.Text, sbCorrupted.ToString());
|
|
foreach (var item in serachDic)
|
|
{
|
|
|
|
|
|
File.WriteAllText(item.Value.GetMainFile(), item.Value.getResult());
|
|
|
|
}
|
|
MessageBox.Show("done");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
MessageBox.Show(ex.ToString());
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|