Exemplo n.º 1
0
    public override bool Update(string updateFile)
    {
        // TODO: This only works for Windows

        // FfMpeg archives have versioned folders in the zip file
        // The 7Zip -spe option does not work for zip files
        // https://sourceforge.net/p/sevenzip/discussion/45798/thread/8cb61347/
        // We need to extract to the root tools folder, that will create a subdir, then rename to the destination folder
        string extractPath = Tools.GetToolsRoot();

        // Extract the update file
        Log.Logger.Information("Extracting {UpdateFile} ...", updateFile);
        if (!Tools.SevenZip.UnZip(updateFile, extractPath))
        {
            return(false);
        }

        // Delete the tool destination directory
        string toolPath = GetToolFolder();

        if (!FileEx.DeleteDirectory(toolPath, true))
        {
            return(false);
        }

        // Build the versioned out folder from the downloaded filename
        // E.g. ffmpeg-3.4-win64-static.zip to .\Tools\FFmpeg\ffmpeg-3.4-win64-static
        extractPath = Tools.CombineToolPath(Path.GetFileNameWithoutExtension(updateFile));

        // Rename the extract folder to the tool folder
        // E.g. ffmpeg-3.4-win64-static to .\Tools\FFMpeg
        return(FileEx.RenameFolder(extractPath, toolPath));
    }
Exemplo n.º 2
0
    public override bool Update(string updateFile)
    {
        // We need to keep the previous copy of 7zip so we can extract the new copy
        // We need to extract to a temp location in the root tools folder, then rename to the destination folder
        // Build the versioned folder from the downloaded filename
        // E.g. 7z1805-extra.7z to .\Tools\7z1805-extra
        string extractPath = Tools.CombineToolPath(Path.GetFileNameWithoutExtension(updateFile));

        // Extract the update file
        Log.Logger.Information("Extracting {UpdateFile} ...", updateFile);
        if (!Tools.SevenZip.UnZip(updateFile, extractPath))
        {
            return(false);
        }

        // Delete the tool destination directory
        string toolPath = GetToolFolder();

        if (!FileEx.DeleteDirectory(toolPath, true))
        {
            return(false);
        }

        // Rename the folder
        // E.g. 7z1805-extra to .\Tools\7Zip
        return(FileEx.RenameFolder(extractPath, toolPath));
    }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the temp directory for this application.
        /// </summary>
        public static void CleanTempDirectory()
        {
            var tempPath = GetTempPath();

            if (!Directory.Exists(tempPath))
            {
                return;
            }
            FileEx.DeleteDirectory(tempPath);
        }
Exemplo n.º 4
0
        public void EnsureDirectoryTest()
        {
            var path = @"C:\Garb\Test\Whatever";

            // If the directory exists, delete it so we can test the Ensure works correctly.
            FileEx.DeleteDirectory(path);

            Assert.IsFalse(Directory.Exists(path));

            FileEx.EnsureDirectory(path);
            Assert.IsTrue(Directory.Exists(path));

            FileEx.EnsureDirectory(path);
            Assert.IsTrue(Directory.Exists(path));
        }
Exemplo n.º 5
0
    public bool BootstrapDownload()
    {
        // Only supported on Windows
        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            return(false);
        }

        // Make sure that the Tools folder exists
        if (!Directory.Exists(Tools.GetToolsRoot()))
        {
            Log.Logger.Warning("Creating missing Tools folder : \"{ToolsRoot}\"", Tools.GetToolsRoot());
            if (!FileEx.CreateDirectory(Tools.GetToolsRoot()))
            {
                return(false);
            }
        }

        // Download 7zr.exe in the tools root folder
        // https://www.7-zip.org/a/7zr.exe
        Log.Logger.Information("Downloading \"7zr.exe\" ...");
        string       sevenZr    = Tools.CombineToolPath("7zr.exe");
        const string sevenZrUrl = "https://www.7-zip.org/a/7zr.exe";

        if (!Download.DownloadFile(new Uri(sevenZrUrl), sevenZr))
        {
            return(false);
        }

        // Get the latest version of 7z
        if (!GetLatestVersionWindows(out MediaToolInfo mediaToolInfo))
        {
            return(false);
        }

        // Download the lastest version in the tools root folder
        Log.Logger.Information("Downloading \"{FileName}\" ...", mediaToolInfo.FileName);
        string updateFile = Tools.CombineToolPath(mediaToolInfo.FileName);

        if (!Download.DownloadFile(new Uri(mediaToolInfo.Url), updateFile))
        {
            return(false);
        }

        // Follow the pattern from Update()

        // Use 7zr.exe to extract the archive to the tools folder
        Log.Logger.Information("Extracting {UpdateFile} ...", updateFile);
        string extractPath = Tools.CombineToolPath(Path.GetFileNameWithoutExtension(updateFile));
        string commandline = $"x -aoa -spe -y \"{updateFile}\" -o\"{extractPath}\"";
        int    exitCode    = ProcessEx.Execute(sevenZr, commandline);

        if (exitCode != 0)
        {
            Log.Logger.Error("Failed to extract archive : ExitCode: {ExitCode}", exitCode);
            return(false);
        }

        // Delete the tool destination directory
        string toolPath = GetToolFolder();

        if (!FileEx.DeleteDirectory(toolPath, true))
        {
            return(false);
        }

        // Rename the folder
        // E.g. 7z1805-extra to .\Tools\7Zip
        return(FileEx.RenameFolder(extractPath, toolPath));
    }