Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CustomUnzipCommandTemplate implementation, for zipped distributions on Windows #219

Closed
wants to merge 2 commits into from

Conversation

carlospeix
Copy link

Hi @Deadpikle,

Thank you for this component!

I just implemented this and wanted to share.

My context is about Windows platform (Windows 10 in fact) and want to use the simpler zip packaging. Given since 2017 Win10 have a standard tar implementation, I decided to implement a small change so we can build the installer command from a template.

This is a simple implementation that only supports .zip extensions (easy to extend, though). I tried hard not to scatter changes all over the code, that's why I didn't used the IsZipDownload() method.

Please let me know if you need further information.

Thanks
Carlos

@Deadpikle
Copy link
Collaborator

Hi @carlospeix,

Thanks for your contribution. I appreciate it when people are willing to contribute!

Unfortunately, I don't really want to accept this PR right now. The tar command is only available from Windows 10 17063 and on, and since we support earlier versions of Windows, I'd rather users implement this themselves until we have support for all Windows operating systems that we support. I didn't know tar was supported on Windows 10 at all, though, so great to know that it's available! That will help #183.

This could be easily accomplished with a subclass in a cleaner way. I haven't tested this code, but something like this should work:

public class MySparkleUpdater : SparkleUpdater
{

    /// <summary>
    /// Use this command template to run the installer (unzipping, for example)
    /// {0} is downloadFilePath
    /// {1} is workingDir (with no trailing backslash)
    /// Example for unzipping Windows 10:
    ///     "tar -x -f {0} -C \"{1}\""
    /// </summary>
    public string CustomUnzipCommandTemplate { get; set; }

    override protected virtual string GetWindowsInstallerCommand(string downloadFilePath)
    {
        string installerExt = Path.GetExtension(downloadFilePath);
        if (DoExtensionsMatch(installerExt, ".exe"))
        {
            return "\"" + downloadFilePath + "\"";
        }
        if (DoExtensionsMatch(installerExt, ".msi"))
        {
            return "msiexec /i \"" + downloadFilePath + "\"";
        }
        if (DoExtensionsMatch(installerExt, ".msp"))
        {
            return "msiexec /p \"" + downloadFilePath + "\"";
        }
        if (DoExtensionsMatch(installerExt, ".zip"))
        {
            if (!string.IsNullOrEmpty(CustomUnzipCommandTemplate))
            {
                return string.Format(CustomUnzipCommandTemplate, downloadFilePath, RestartExecutablePath.TrimEnd('\\'));
            }
            return string.Format("tar -x -f {0} -C \"{1}\"", downloadFilePath, RestartExecutablePath.TrimEnd('\\'));
        }
        return downloadFilePath;
    }
}

The IsZipDownload would have to be cleaned up if we were to add official zip support to Windows, though.

@carlospeix
Copy link
Author

carlospeix commented Jul 15, 2021

Hi @Deadpikle, thank you for your recommendation! Looks good to me. I already implemented it and works fine.

This is the implementation of the class (just added the constructors), just in case somebody needs it.

public class MySparkleUpdater : SparkleUpdater
    {
        public MySparkleUpdater(string appcastUrl, ISignatureVerifier signatureVerifier) :
            base(appcastUrl, signatureVerifier) { }
        public MySparkleUpdater(string appcastUrl, ISignatureVerifier signatureVerifier, string referenceAssembly) :
            base(appcastUrl, signatureVerifier, referenceAssembly) { }
        public MySparkleUpdater(string appcastUrl, ISignatureVerifier signatureVerifier, string referenceAssembly, IUIFactory factory) :
            base(appcastUrl, signatureVerifier, referenceAssembly, factory) { }

        /// <summary>
        /// Use this command template to run the installer (unzipping, for example)
        /// {0} is downloadFilePath
        /// {1} is workingDir (with no trailing backslash)
        /// Example for unzipping Windows 10:
        ///     "tar -x -f {0} -C \"{1}\""
        /// </summary>
        public string CustomUnzipCommandTemplate { get; set; }

        protected override string GetWindowsInstallerCommand(string downloadFilePath)
        {
            string installerExt = Path.GetExtension(downloadFilePath);
            if (DoExtensionsMatch(installerExt, ".exe"))
            {
                return "\"" + downloadFilePath + "\"";
            }
            if (DoExtensionsMatch(installerExt, ".msi"))
            {
                return "msiexec /i \"" + downloadFilePath + "\"";
            }
            if (DoExtensionsMatch(installerExt, ".msp"))
            {
                return "msiexec /p \"" + downloadFilePath + "\"";
            }
            if (DoExtensionsMatch(installerExt, ".zip"))
            {
                if (!string.IsNullOrEmpty(CustomUnzipCommandTemplate))
                {
                    return string.Format(CustomUnzipCommandTemplate, downloadFilePath, RestartExecutablePath.TrimEnd('\\'));
                }
                return string.Format("tar -x -f {0} -C \"{1}\"", downloadFilePath, RestartExecutablePath.TrimEnd('\\'));
            }
            return downloadFilePath;
        }
    }

I assume that you will discard the PR, please let me know if I should do something.

Thank you very much for your time.

This pull request was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
no merge Will not merge this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants