This is a simple winforms application that will split it, done in C#. It needs three buttons: btnIn
, btnFolder
, btnSplit
and two labels, lblIn
, lblFolder
.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PatchSplitter {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void btnIn_Click(object sender, EventArgs e) {
OpenFileDialog ofd = new OpenFileDialog();
if(ofd.ShowDialog() == DialogResult.OK) {
lblIn.Text = ofd.FileName;
if(lblIn.Text != "" && lblFolder.Text != "") {
btnSplit.Enabled = true;
} else {
btnSplit.Enabled = false;
}
}
}
private void btnFolder_Click(object sender, EventArgs e) {
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK) {
lblFolder.Text = fbd.SelectedPath;
if (lblIn.Text != "" && lblFolder.Text != "") {
btnSplit.Enabled = true;
} else {
btnSplit.Enabled = false;
}
}
}
private void btnSplit_Click(object sender, EventArgs e) {
string file = "";
string line;
StreamWriter current = null;
StreamReader input = new StreamReader(lblIn.Text);
while ((line = input.ReadLine()) != null) {
if (line.StartsWith("Index: ")) {
if (current != null) {
current.Close();
}
file = line.Remove(0, 7);
string directory;
if (file.LastIndexOf('/') == -1) {
directory = "";
} else {
directory = file.Substring(0, file.LastIndexOf('/'));
}
if (!Directory.Exists(lblFolder.Text + "\\" + directory)) {
Directory.CreateDirectory(lblFolder.Text + "\\" + directory);
}
current = new StreamWriter(new FileStream(lblFolder.Text + "\\" + file + ".patch", FileMode.Create));
current.WriteLine(line);
} else {
if (current != null) {
current.WriteLine(line);
}
}
}
current.Close();
MessageBox.Show("Done");
}
}
}