Skip to content

Instantly share code, notes, and snippets.

@stuartd
Last active June 4, 2019 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartd/8cff12c4625cf619dd5ccd14939237a1 to your computer and use it in GitHub Desktop.
Save stuartd/8cff12c4625cf619dd5ccd14939237a1 to your computer and use it in GitHub Desktop.
using System;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace ClipboardDiff {
class Program {
static void Main(string[] args) {
string text1 = null;
string text2 = null;
var sql = "select ooData from data where strClipBoardFormat = 'CF_TEXT' and LParentId in (select lId from main order by lID desc limit 2)";
using (var connection = new SQLiteConnection("Data Source=C:\\Users\\stuartd\\AppData\\Roaming\\Ditto\\Ditto.db;Version=3;")) {
using (var command = new SQLiteCommand(sql, connection)) {
command.Prepare();
connection.Open();
using (var reader = command.ExecuteReader()) {
string GetValue() {
var bytes = (byte[]) reader.GetValue(0);
return System.Text.Encoding.UTF8.GetString(bytes.Where(b => b != 0).ToArray());
}
if (reader.Read()) {
text1 = GetValue();
}
if (reader.Read()) {
text2 = GetValue();
}
}
}
}
if (!string.IsNullOrEmpty(text1) && !string.IsNullOrEmpty(text2)) {
var tempFile1 = Path.GetTempFileName();
File.WriteAllText(tempFile1, text1);
var tempFile2 = Path.GetTempFileName();
File.WriteAllText(tempFile2, text2);
var processData = new ProcessStartInfo {
FileName = @"C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe",
Arguments = $"/title1=1 /title2=2 {tempFile1} {tempFile2}",
UseShellExecute = true
};
Process.Start(processData);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment