Пример #1
0
        /// <summary>
        /// Renames a replay according to a custom replay format.
        /// </summary>
        /// <param name="replay">The replay to rename.</param>
        /// <param name="format">The custom replay format to use to rename the replay.</param>
        /// <param name="forward">Whether to move the file history pointer forward or not.</param>
        /// <exception cref="ArgumentNullException">Throws an ArgumentNullException in case replay or format is null.</exception>
        public static void RenameReplay(File <IReplay> replay, CustomReplayFormat format, bool forward = true)
        {
            var newName = GenerateReplayName(replay, format);

            replay.AddAfterCurrent(newName);
            if (forward)
            {
                replay.Forward();
            }
        }
Пример #2
0
        public static void MoveReplay(File <IReplay> replay, string sortDirectory, string folderName, bool keepOriginalReplayNames, CustomReplayFormat customReplayFormat, bool isPreview = false)
        {
            if (replay == null)
            {
                throw new ArgumentNullException(nameof(replay));
            }
            if (string.IsNullOrWhiteSpace(sortDirectory))
            {
                throw new ArgumentException(nameof(sortDirectory));
            }
            if (!keepOriginalReplayNames && customReplayFormat == null)
            {
                throw new InvalidOperationException($"{nameof(customReplayFormat)} cannot be null if {nameof(keepOriginalReplayNames)} is false!");
            }

            var       sourceFilePath      = replay.FilePath;
            var       fileName            = FileHandler.GetFileName(replay.FilePath);
            var       destinationFilePath = Path.Combine(sortDirectory, folderName, fileName);
            var       renamedSuccessfully = true;
            Exception renameException     = null;

            if (!keepOriginalReplayNames)
            {
                try
                {
                    destinationFilePath = sortDirectory + @"\" + folderName + @"\" + GenerateReplayName(replay, customReplayFormat) + ".rep";
                }
                catch (Exception ex)
                {
                    renamedSuccessfully = false;
                    renameException     = ex;
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - Error while renaming replay: {replay.OriginalFilePath}", ex: ex);
                }
            }

            destinationFilePath = FileHandler.AdjustName(destinationFilePath, false);

            if (!isPreview)
            {
                File.Move(sourceFilePath, destinationFilePath);
            }

            replay.AddAfterCurrent(destinationFilePath);
            replay.Forward();

            if (!renamedSuccessfully)
            {
                throw new RenameException(sourceFilePath, customReplayFormat, $"Something went wrong while renaming.", renameException);
            }
        }
Пример #3
0
        public static void CopyReplay(File <IReplay> replay, string newReplayPath, bool isPreview = false)
        {
            if (replay == null)
            {
                throw new ArgumentNullException(nameof(replay));
            }
            if (string.IsNullOrWhiteSpace(newReplayPath))
            {
                throw new ArgumentException(newReplayPath);
            }

            newReplayPath = FileHandler.AdjustName(newReplayPath, false);

            if (!isPreview)
            {
                File.Copy(replay.FilePath, newReplayPath);
            }

            replay.AddAfterCurrent(newReplayPath);
            replay.Forward();
        }