コード例 #1
0
ファイル: FontsManager.cs プロジェクト: WildGenie/actools
        public override void Rename(string id, string newFileName, bool newEnabled)
        {
            if (!Directories.Actual)
            {
                return;
            }
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var wrapper = GetWrapperById(id);

            if (wrapper == null)
            {
                throw new ArgumentException(ToolsStrings.AcObject_IdIsWrong, nameof(id));
            }

            var currentLocation       = ((AcCommonObject)wrapper.Value).Location;
            var currentBitmapLocation = ((FontObject)wrapper.Value).FontBitmap;
            var path = newEnabled ? Directories.EnabledDirectory : Directories.DisabledDirectory;

            if (path == null)
            {
                throw new ToggleException(ToolsStrings.AcObject_CannotBeMoved);
            }

            var newLocation       = Path.Combine(path, newFileName);
            var newBitmapLocation = currentBitmapLocation == null
                    ? null : Path.Combine(path, Path.GetFileNameWithoutExtension(newLocation) + Path.GetExtension(currentBitmapLocation));

            if (FileUtils.Exists(newLocation) || currentBitmapLocation != null && File.Exists(newBitmapLocation))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            try {
                using (IgnoreChanges()) {
                    FileUtils.Move(currentLocation, newLocation);

                    if (currentBitmapLocation != null)
                    {
                        FileUtils.Move(currentBitmapLocation, newBitmapLocation);
                    }

                    var obj = CreateAndLoadAcObject(newFileName, Directories.CheckIfEnabled(newLocation));
                    obj.PreviousId = id;
                    ReplaceInList(id, new AcItemWrapper(this, obj));

                    UpdateList();
                }
            } catch (Exception e) {
                throw new ToggleException(e.Message);
            }
        }
コード例 #2
0
        public override void Rename(string id, string newFileName, bool newEnabled)
        {
            if (!Directories.Actual)
            {
                return;
            }
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var wrapper = GetWrapperById(id);

            if (wrapper == null)
            {
                throw new ArgumentException(ToolsStrings.AcObject_IdIsWrong, nameof(id));
            }

            var currentLocation = ((AcCommonObject)wrapper.Value).Location;
            var currentExtended = ((UserChampionshipObject)wrapper.Value).ExtendedFilename;
            var currentPreview  = ((UserChampionshipObject)wrapper.Value).PreviewImage;

            var path = newEnabled ? Directories.EnabledDirectory : Directories.DisabledDirectory;

            if (path == null)
            {
                throw new ToggleException(ToolsStrings.AcObject_CannotBeMoved);
            }

            if (!File.Exists(currentExtended))
            {
                currentExtended = null;
            }

            if (!File.Exists(currentPreview))
            {
                currentPreview = null;
            }

            var newLocation = Path.Combine(path, newFileName);
            var newBasePart = Path.GetFileName(newLocation).ApartFromLast(UserChampionshipObject.FileExtension);
            var newExtended = currentExtended == null ? null : Path.Combine(path, newBasePart + UserChampionshipObject.FileDataExtension);
            var newPreview  = currentPreview == null ? null : Path.Combine(path, newBasePart + UserChampionshipObject.FilePreviewExtension);

            if (FileUtils.Exists(newLocation) ||
                currentExtended != null && File.Exists(newExtended) ||
                currentPreview != null && File.Exists(newPreview))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            try {
                using (IgnoreChanges()) {
                    FileUtils.Move(currentLocation, newLocation);

                    if (currentExtended != null)
                    {
                        FileUtils.Move(currentExtended, newExtended);
                    }

                    if (currentPreview != null)
                    {
                        FileUtils.Move(currentPreview, newPreview);
                    }

                    var obj = CreateAndLoadAcObject(newFileName, Directories.CheckIfEnabled(newLocation));
                    obj.PreviousId = id;
                    ReplaceInList(id, new AcItemWrapper(this, obj));

                    UpdateList();
                }
            } catch (Exception e) {
                throw new ToggleException(e.Message);
            }
        }