Пример #1
0
        public byte[] CalculateSha256(string filePath)
        {
            filePath = NormalizeAndEvaluate(filePath);

            using (var algorithm = SHA256.Create())
                using (var stream = _filesystem.OpenRead(filePath))
                {
                    return(HashCodeCalculator.CalculateHash(stream, algorithm));
                }
        }
Пример #2
0
        public PluginGroup OpenPlugin(string pluginPath)
        {
            var stream = _filesystem.OpenRead(pluginPath);

            try
            {
                // Ownership of the stream transfers to PluginArchive which is disposed of when this class is
                // disposed of....
                var archive = PluginArchive.OpenRead(stream);
                return(Add(pluginPath, archive));
            }
            catch (Exception)
            {
                stream.Dispose();
                throw;
            }
        }
Пример #3
0
        /// <summary>
        ///     Tries to open the file at the given path as a tailviewer plugin.
        ///     Succeeds if the file is a zip archive and its metadata could be read.
        ///     The plugin itself is not loaded until later.
        /// </summary>
        /// <param name="pluginPath"></param>
        private void TryOpenPlugin(string pluginPath)
        {
            Log.DebugFormat("Loading plugin '{0}'...", pluginPath);

            ExtractIdAndVersion(pluginPath, out var id, out var version);
            try
            {
                // DO NOT DISPOSE OF THE STREAM HERE!!!
                // Ownership transfers to PluginArchive which is disposed of when this class is
                // disposed of....
                var stream  = _filesystem.OpenRead(pluginPath).Result;
                var archive = PluginArchive.OpenRead(stream);
                Add(pluginPath, id, version, archive);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Unable to load '{0}': {1}", pluginPath, e);
                Add(pluginPath, id, version, new EmptyPluginArchive(version));
            }
        }