Beispiel #1
0
        private static void ParseAndCheck(Stream stream)
        {
            var recoverDirPath = new DirectoryPath(RecoveryFolder);

            recoverDirPath.EnsureExists();

            int r, moved = 0;
            var buffer = new byte[4096];

            while ((r = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                for (r--; r >= 0; r--)
                {
                    var slotId = Convert.ToInt32(buffer[r]);

                    if (CheckAndMoveNonEmptyFileSlots(slotId, recoverDirPath))
                    {
                        moved++;
                    }
                }
            }

            if (moved > 0)
            {
                SendFileMovedNotification(moved);
            }
        }
Beispiel #2
0
        /// <summary>Instantiates a new package manager</summary>
        /// <param name="pluginDirPath"></param>
        /// <param name="pluginHomeDirPath"></param>
        /// <param name="packageDirPath"></param>
        /// <param name="configFilePath"></param>
        /// <param name="providerCreator"></param>
        /// <returns></returns>
        public static async Task <PluginPackageManager <TMeta> > Create(
            DirectoryPath pluginDirPath,
            DirectoryPath pluginHomeDirPath,
            DirectoryPath packageDirPath,
            FilePath configFilePath,
            Func <ISettings, NuGet.SourceRepositoryProvider> providerCreator = null)
        {
            pluginDirPath  = pluginDirPath.Collapse();
            packageDirPath = packageDirPath.Collapse();

            if (pluginDirPath.EnsureExists() == false)
            {
                throw new ArgumentException($"Root path {pluginDirPath.FullPath} doesn't exist and couldn't be created.");
            }

            if (packageDirPath.EnsureExists() == false)
            {
                throw new ArgumentException($"Package path {packageDirPath.FullPath} doesn't exist and couldn't be created.");
            }

            if (configFilePath.Directory.Exists() == false)
            {
                throw new ArgumentException($"Config file's directory {configFilePath.Directory.FullPath} doesn't exist and couldn't be created.");
            }

            var packageCache = await NuGetInstalledPluginRepository <TMeta> .LoadAsync(configFilePath, pluginHomeDirPath);

            return(new PluginPackageManager <TMeta>(
                       pluginDirPath,
                       pluginHomeDirPath,
                       packageDirPath,
                       packageCache,
                       providerCreator));
        }
Beispiel #3
0
        private static bool CheckAndMoveNonEmptyFileSlots(int slotId, DirectoryPath recoverDirPath)
        {
            var wildCardPath     = RegistryMemberBase.GetFilePathForSlotId(Core.SM.Collection, slotId, "*");
            var fileNameWildCard = Path.GetFileName(wildCardPath);
            var dirPath          = Path.GetDirectoryName(wildCardPath);

            fileNameWildCard.ThrowIfNullOrWhitespace("fileNameWildCard was null or whitespace");
            dirPath.ThrowIfNullOrWhitespace("dirPath was null or whitespace");

            recoverDirPath.EnsureExists();

            bool moved = false;

            // TODO: Does there need to be a loop - only looking for one file?
            foreach (var filePath in Directory.EnumerateFiles(dirPath, fileNameWildCard, SearchOption.TopDirectoryOnly))
            {
                try
                {
                    // TODO: What if there is already a file in recover dir with the same name

                    var date     = DateTime.Today;
                    var fileName = $"{date.Day}-{date.Month}-{date.Year}_{Path.GetFileName(filePath)}";
                    File.Move(filePath, recoverDirPath.CombineFile(fileName).FullPath);
                    moved = true;
                }
                catch (IOException ex)
                {
                    LogTo.Warning(ex, "Failed to move non-empty fileslot file {FilePath}", filePath);

                    if (File.Exists(filePath))
                    {
                        throw new InvalidOperationException($"Failed to remove non-empty fileslot file {filePath}");
                    }
                }
            }

            return(moved);
        }