Menu

[38707f]: / ClassDiff.cs  Maximize  Restore  History

Download this file

123 lines (109 with data), 6.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
namespace GitForce
{
/// <summary>
/// Manage various diff programs and diff execution
/// </summary>
public class ClassDiff
{
// Common diff utilities:
//
// We bundle together Windows and Linux utilities
// Since we build this app in 32-bit mode, on 64-bit OS Windows Program Files will return a (x86) folder variant
private static readonly string ProgramFilesX86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
private static readonly string ProgramFilesX64 = ProgramFilesX86.Contains(" (x86)") ? ProgramFilesX86.Replace(" (x86)", "") : ProgramFilesX86;
private static readonly List<AppHelper> Candidates = new List<AppHelper> {
// Config Short name Path Arguments
// Windows OS (x32):
new AppHelper( "p4merge", Path.Combine(ProgramFilesX86,@"Perforce\P4Merge.exe"), "%1 %2" ),
new AppHelper( "WinMerge", Path.Combine(ProgramFilesX86,@"WinMerge\WinMergeU.exe"), "/e /x /u %1 %2" ),
new AppHelper( "BC3", Path.Combine(ProgramFilesX86,@"Beyond Compare 3\BComp.com"), "%1 %2" ),
new AppHelper( "BC4", Path.Combine(ProgramFilesX86,@"Beyond Compare 4\BComp.com"), "%1 %2" ),
new AppHelper( "KDiff3", Path.Combine(ProgramFilesX86,@"KDiff3\kdiff3.exe"), "%1 %2" ),
new AppHelper( "Meld", Path.Combine(ProgramFilesX64,@"Meld\Meld.exe"), "%1 %2" ),
// Windows OS (x64):
new AppHelper( "p4merge", Path.Combine(ProgramFilesX64,@"Perforce\P4Merge.exe"), "%1 %2" ),
new AppHelper( "WinMerge", Path.Combine(ProgramFilesX64,@"WinMerge\WinMergeU.exe"), "/e /x /u %1 %2" ),
new AppHelper( "BC3", Path.Combine(ProgramFilesX64,@"Beyond Compare 3\BComp.com"), "%1 %2" ),
new AppHelper( "BC4", Path.Combine(ProgramFilesX64,@"Beyond Compare 4\BComp.com"), "%1 %2" ),
new AppHelper( "BC5", Path.Combine(ProgramFilesX64,@"Beyond Compare 5\BComp.com"), "%1 %2" ),
new AppHelper( "KDiff3", Path.Combine(ProgramFilesX64,@"KDiff3\kdiff3.exe"), "%1 %2" ),
new AppHelper( "Meld", Path.Combine(ProgramFilesX64,@"Meld\Meld.exe"), "%1 %2" ),
// Linux OS:
new AppHelper( "KDiff3", @"/usr/bin/kdiff3", "%1 %2" ),
new AppHelper( "TKDiff", @"/usr/bin/tkdiff", "%1 %2" ),
new AppHelper( "Meld", @"/usr/bin/meld", "%1 %2" ),
new AppHelper( "xxdiff", @"/usr/bin/xxdiff", "%1 %2" ),
new AppHelper( "Diffuse", @"/usr/bin/diffuse", "%1 %2" ),
new AppHelper( "BCompare", @"/usr/bin/bcompare", "%1 %2" ),
};
private List<AppHelper> diff = new List<AppHelper>();
/// <summary>
/// Init code to be called on the application startup.
/// Return false if no diff utility was found and user wanted to quit the app.
/// </summary>
public bool Initialize()
{
// Verify the application default diff utility
AppHelper app = new AppHelper(Properties.Settings.Default.DiffAppHelper);
if (File.Exists(app.Path))
{
Configure(app);
return true;
}
// Search for any of the predefined tools
diff = GetDetected();
// If none of the pre-set diff apps are present, show the missing diff dialog
// and return with its selection of whether to continue or quit the app
if (diff.Count == 0)
{
FormDiffMissing formDiffMissing = new FormDiffMissing();
return formDiffMissing.ShowDialog() == DialogResult.OK;
}
// Otherwise, at least one diff app is present, select it as default
Properties.Settings.Default.DiffAppHelper = diff[0].ToString();
Configure(diff[0]);
return true;
}
/// <summary>
/// Configure a given application helper to be a Git diff utility
/// </summary>
public static void Configure(AppHelper app)
{
// Configure application only if it is valid
if (app.Name != string.Empty)
{
string path = app.Path.Replace('\\', '/');
string usr = app.Args.
Replace("%1", "$LOCAL").
Replace("%2", "$REMOTE");
string arg = "'" + path + "' " + usr;
ClassConfig.SetGlobal("difftool." + app.Name + ".path", path);
ClassConfig.SetGlobal("difftool." + app.Name + ".cmd", arg);
// TODO: This might be an option: Set our default tool to be the Git gui tool?
// ClassConfig.SetGlobal("diff.guitool", app.Name);
}
}
/// <summary>
/// Return a proper diff command.
/// This function is called from the actual menu item to diff files.
/// </summary>
public static string GetDiffCmd()
{
// Get the application default visual diff utility
AppHelper app = new AppHelper(Properties.Settings.Default.DiffAppHelper);
string cmd = string.Format(" --tool={0} --no-prompt ", app.Name);
return cmd;
}
/// <summary>
/// Returns a list of detected diff application helpers
/// </summary>
public static List<AppHelper> GetDetected()
{
return AppHelper.Scan(Candidates);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.