Skip to content

Commit

Permalink
Ensure git Unicode filename mode is enabled
Browse files Browse the repository at this point in the history
Fixed Regex git version checking bugs
Show native Windows dialog when missing features detected
Fixed null-ref when renaming branches
Added missing app.manifest file
  • Loading branch information
zezba9000 committed Nov 2, 2021
1 parent df671f2 commit 2efd709
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 29 deletions.
2 changes: 1 addition & 1 deletion GitCommander/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public static class VersionInfo
{
public const string version = "1.0.7";
public const string version = "1.0.8";

#if DEBUG
public const string versionType = version + "d";
Expand Down
40 changes: 40 additions & 0 deletions GitCommander/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,45 @@ public bool GetVersion(out string version)
return result;
}
}

public bool EnsureUnicodeDisabledLocally()
{
bool unicodeEntryExists = false;
void stdCallback(string line)
{
if (line != null) unicodeEntryExists = true;
}

lock (this)
{
if (!SimpleGitInvoke("config --local core.quotepath", stdCallback:stdCallback)) return false;
if (unicodeEntryExists)
{
if (!SimpleGitInvoke("config --local --unset core.quotepath")) return false;
}

return true;
}
}

public bool EnsureUnicodeEnabledGlobally()
{
bool unicodeEnabled = false;;
void stdCallback(string line)
{
if (line == "off") unicodeEnabled = true;
}

lock (this)
{
if (!SimpleGitInvoke("config --global core.quotepath", stdCallback:stdCallback)) return false;
if (!unicodeEnabled)
{
return SimpleGitInvoke("config --global core.quotepath off");
}

return true;
}
}
}
}
3 changes: 2 additions & 1 deletion GitCommander/Repository_Changes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@ bool addState(string type, FileStates stateType, FileConflictTypes conflictType
}
else
{
var ext = Path.GetExtension(filePath);
var state = new FileState()
{
filename = filePath,
state = stateType,
conflictType = conflictType,
isSubmodule = isSubmodule,
isLFS = lfsExts.Contains(Path.GetExtension(filePath))
isLFS = lfsExts.Contains(ext)
};

states.Add(state);
Expand Down
29 changes: 16 additions & 13 deletions GitItGUI.Core/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public enum UpdateCheckResult
BadVersionError,
GitVersionCheckError,
GitLFSVersionCheckError,
GitVersionToLowForLFS
GitVersionToLowForLFS,
UnicodeSettingsFailed
}

public delegate void CheckForUpdatesCallbackMethod(UpdateCheckResult result);
Expand Down Expand Up @@ -216,7 +217,7 @@ public static void Dispose()
DebugLog.Dispose();
}

public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod checkForUpdatesCallback)
public static void ValidateSystem(string url, CheckForUpdatesCallbackMethod checkForUpdatesCallback)
{
try
{
Expand All @@ -236,7 +237,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che
catch
{
DebugLog.LogError("git is not installed correctly. (Make sure git is usable in the cmd/terminal)");
client.Dispose();
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitNotInstalledError);
DownloadGit();
return;
Expand All @@ -250,30 +250,24 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che
catch
{
DebugLog.LogError("git-lfs is not installed correctly. (Make sure git-lfs is usable in the cmd/terminal)");
client.Dispose();
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitLFSNotInstalledError);
DownloadGitLFS();
return;
}

// grab git version value
string appendix = "";
if (PlatformInfo.platform == Platforms.Windows) appendix = @"\.windows";
var match = Regex.Match(gitVersion, @"git version (.*)" + appendix);
var match = Regex.Match(gitVersion, @"git version (\d*\.\d*\.\d*)");
if (match.Success && match.Groups.Count == 2) gitVersion = match.Groups[1].Value;
else
{
DebugLog.LogError("Failed to grab git version!");
client.Dispose();
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitVersionCheckError);
DownloadGit();
return;
}

// grab lfs and required git version value
if (PlatformInfo.platform == Platforms.Windows) appendix = @"; git .*\)";
else appendix = @"\)";
match = Regex.Match(gitlfsVersion, @"git-lfs/(.*) \(GitHub; (\w*) (\w*); go (.*)" + appendix);
match = Regex.Match(gitlfsVersion, @"git-lfs/(\d*\.\d*\.\d*) \(GitHub; (\w*) (\w*); go (\d*\.\d*\.\d*)");
if (match.Success && match.Groups.Count == 5)
{
gitlfsVersion = match.Groups[1].Value;
Expand All @@ -282,7 +276,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che
else
{
DebugLog.LogError("Failed to grab git-lfs version!");
client.Dispose();
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitLFSVersionCheckError);
DownloadGitLFS();
return;
Expand All @@ -292,7 +285,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che
if (!IsValidVersion(gitVersion, gitlfsRequiredGitVersion))
{
DebugLog.LogError(string.Format("'git-lfs' version is not compatible with 'git' version installed!"));
client.Dispose();
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitVersionToLowForLFS);
DownloadGit();
DownloadGitLFS();
Expand Down Expand Up @@ -321,6 +313,14 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che
return;
}

// make sure git prints unicode filenames
if (!repository.EnsureUnicodeEnabledGlobally())
{
DebugLog.LogError("Git unicode support is not enabled or failed to be enabled!");
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.UnicodeSettingsFailed);
return;
}

// check app version
client = new WebClient();
client.DownloadStringCompleted += Client_DownloadStringCompleted;
Expand Down Expand Up @@ -419,6 +419,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString
{
DebugLog.LogError("Failed to check for updates: " + e.Error.Message);
client.Dispose();
client = null;
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.CommonError);
return;
}
Expand All @@ -427,6 +428,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString
{
DebugLog.LogError("Update check canceled!");
client.Dispose();
client = null;
if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.CommonError);
return;
}
Expand Down Expand Up @@ -461,6 +463,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString
}

client.Dispose();
client = null;
}
}
}
3 changes: 3 additions & 0 deletions GitItGUI.Core/RepoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public bool Open(string repoPath, bool checkForSettingErros = false)
// load repo
if (isRefreshMode) repository.Close();
if (!repository.Open(repoPath)) throw new Exception(repository.lastError);

// validate unicode is disabled locally
if (!repository.EnsureUnicodeDisabledLocally()) return false;

// check for git lfs
lfsEnabled = repository.lfs.isEnabled;
Expand Down
5 changes: 4 additions & 1 deletion GitItGUI.UI/GitItGUI.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-x64, Version=8.2.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=AMD64">
<HintPath>..\packages\Magick.NET-Q16-x64.8.2.1\lib\net20\Magick.NET-Q16-x64.dll</HintPath>
Expand Down Expand Up @@ -232,6 +235,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -243,7 +247,6 @@
</ItemGroup>
<ItemGroup>
<Resource Include="Images\UpdateFlash.png" />
<None Include="VersionInfo.xml" />
<Resource Include="Images\CheckPattern.png" />
<Resource Include="Images\Update.png" />
<Resource Include="Images\UserTask.png" />
Expand Down
25 changes: 17 additions & 8 deletions GitItGUI.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public partial class MainWindow : Window
public MainWindow()
{
// UnhandledException
#if !DEBUG
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
#endif

// init debug log
DebugLog.Log("Git-It-GUI v" + VersionInfo.version + Environment.NewLine);
Expand Down Expand Up @@ -68,9 +70,9 @@ public MainWindow()
if (AppManager.settings.winMaximized) WindowState = WindowState.Maximized;
}

// version check
// validate system
Title += " v" + VersionInfo.versionType;
AppManager.CheckForUpdates("http://reign-studios-services.com/GitItGUI/VersionInfo.xml", CheckForUpdatesCallback);
AppManager.ValidateSystem("http://reign-studios-services.com/GitItGUI/VersionInfo.xml", CheckForUpdatesCallback);
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down Expand Up @@ -115,21 +117,28 @@ internal void Dispatcher_UnhandledException(object sender, System.Windows.Thread
Environment.Exit(2);
}

public void ShowSystemErrorMessageBox(string title, string message)
{
MessageBox.Show(this, message, title, MessageBoxButton.OK, MessageBoxImage.Error);
}

private void CheckForUpdatesCallback(UpdateCheckResult result)
{
Dispatcher.InvokeAsync(delegate()
{
bool shouldExit = true;
switch (result)
{
case UpdateCheckResult.BadVersionError: ShowMessageOverlay("Error", "Git or (git-lfs) versions are incompatible with this app"); break;
case UpdateCheckResult.GitVersionToLowForLFS: ShowMessageOverlay("Error", "The git version installed is incompatible with the lfs version isntalled"); break;
case UpdateCheckResult.BadVersionError: ShowSystemErrorMessageBox("Error", "Git or (git-lfs) versions are incompatible with this app"); break;
case UpdateCheckResult.GitVersionToLowForLFS: ShowSystemErrorMessageBox("Error", "The git version installed is incompatible with the lfs version isntalled"); break;

case UpdateCheckResult.GitNotInstalledError: ShowMessageOverlay("Error", "Git is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break;
case UpdateCheckResult.GitLFSNotInstalledError: ShowMessageOverlay("Error", "Git-LFS is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break;
case UpdateCheckResult.GitNotInstalledError: ShowSystemErrorMessageBox("Error", "Git is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break;
case UpdateCheckResult.GitLFSNotInstalledError: ShowSystemErrorMessageBox("Error", "Git-LFS is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break;

case UpdateCheckResult.GitVersionCheckError: ShowMessageOverlay("Error", "Git version parse failed.\nIts possible the git version you're using isn't supported"); break;
case UpdateCheckResult.GitLFSVersionCheckError: ShowMessageOverlay("Error", "Git-LFS version parse failed.\nIts possible the git-lfs version you're using isn't supported"); break;
case UpdateCheckResult.GitVersionCheckError: ShowSystemErrorMessageBox("Error", "Git version parse failed.\nIts possible the git version you're using isn't supported"); break;
case UpdateCheckResult.GitLFSVersionCheckError: ShowSystemErrorMessageBox("Error", "Git-LFS version parse failed.\nIts possible the git-lfs version you're using isn't supported"); break;

case UpdateCheckResult.UnicodeSettingsFailed: ShowSystemErrorMessageBox("Error", "Git unicode support is not enabled or failed to be enabled!"); break;

case UpdateCheckResult.AppVersionOutOfDate:
shouldExit = false;
Expand Down
7 changes: 6 additions & 1 deletion GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ private void okButton_Click(object sender, RoutedEventArgs e)
{
Visibility = Visibility.Hidden;
var item = (ComboBoxItem)remoteComboBox.SelectedItem;
if (doneCallback != null) doneCallback(nameTextBox.Text, item.Content as string, true);
if (doneCallback != null)
{
string remoteName = null;
if (item != null) remoteName = item.Content as string;
doneCallback(nameTextBox.Text, remoteName, true);
}
}
}
}
79 changes: 79 additions & 0 deletions GitItGUI.UI/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

</application>
</compatibility>

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config.
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->

</assembly>
6 changes: 3 additions & 3 deletions Installer/Git-It-GUI_Installer.aip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT Type="Advanced Installer" CreateVersion="13.5" version="18.6.1" Modules="simple" RootPath="." Language="en" Id="{C7F5B7C6-44E5-4AFF-8FCE-81E9836F6364}">
<DOCUMENT Type="Advanced Installer" CreateVersion="13.5" version="18.8" Modules="simple" RootPath="." Language="en" Id="{C7F5B7C6-44E5-4AFF-8FCE-81E9836F6364}">
<COMPONENT cid="caphyon.advinst.msicomp.MsiPropsComponent">
<ROW Property="AI_BITMAP_DISPLAY_MODE" Value="0"/>
<ROW Property="AI_CURRENT_YEAR" Value="2021" ValueLocId="-"/>
Expand All @@ -11,10 +11,10 @@
<ROW Property="ARPURLUPDATEINFO" Value="https://github.com/reignstudios/Git-It-GUI/releases"/>
<ROW Property="CTRLS" Value="2"/>
<ROW Property="Manufacturer" Value="Reign-Studios"/>
<ROW Property="ProductCode" Value="1033:{222D0921-88FB-4F2F-9064-FD785E053394} " Type="16"/>
<ROW Property="ProductCode" Value="1033:{82EDB006-8B4B-4FAD-8166-1399CC01A21D} " Type="16"/>
<ROW Property="ProductLanguage" Value="1033"/>
<ROW Property="ProductName" Value="Git-It-GUI"/>
<ROW Property="ProductVersion" Value="1.0.7" Type="32"/>
<ROW Property="ProductVersion" Value="1.0.8" Type="32"/>
<ROW Property="RUNAPPLICATION" Value="1" Type="4"/>
<ROW Property="SecureCustomProperties" Value="OLDPRODUCTS;AI_NEWERPRODUCTFOUND"/>
<ROW Property="UpgradeCode" Value="{FD4A5E78-F668-42CE-90BC-D1DDAA792189}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<VersionInfo>
<AppVersion>1.0.6</AppVersion>
<AppVersion>1.0.8</AppVersion>
</VersionInfo>

0 comments on commit 2efd709

Please sign in to comment.