Gridarta Editor
PathManager.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.io;
21 
22 import java.io.File;
27 import net.sf.gridarta.utils.IOUtils;
29 import org.jetbrains.annotations.NotNull;
30 
39 public class PathManager {
40 
44  @NotNull
46 
52  public PathManager(@NotNull final ProjectSettings projectSettings) {
53  this.projectSettings = projectSettings;
54  }
55 
61  @NotNull
62  public String getMapPath(@NotNull final File file) {
64  }
65 
71  @NotNull
72  public MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath) {
73  return new MapFile(new MapFile(projectSettings.getMapsDirectory()), mapPath);
74  }
75 
83  @NotNull
84  public MapFile getMapFile(@NotNull final File file) {
85  final String canonicalFile = IOUtils.getCanonicalPath(file);
86  final File mapsDirectory = projectSettings.getMapsDirectory();
87  final String canonicalMapsDir = IOUtils.getCanonicalPath(mapsDirectory) + "/";
88  final String mapPath;
89  final File baseDir;
90  if (canonicalFile.startsWith(canonicalMapsDir)) {
91  // within maps directory => base on maps directory
92  mapPath = canonicalFile.substring(canonicalMapsDir.length());
93  baseDir = mapsDirectory;
94  } else {
95  // outside maps directory => base on filesystem root
96  mapPath = canonicalFile;
97  final boolean isWindows = System.getProperty("os.name").contains("Windows");
98  baseDir = (isWindows) ? new File("//./") : new File("/");
99  }
100  return new MapFile(new MapFile(baseDir), MapPathUtils.newMapPath(mapPath));
101  }
102 
103 }
net.sf.gridarta.model.mapmodel.AbsoluteMapPath
A MapPath that is absolute, that is, it starts with a "/".
Definition: AbsoluteMapPath.java:29
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.model.io.PathManager
This class contains methods for converting relative map paths to absolute map paths and vice versa.
Definition: PathManager.java:39
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.mapmodel.MapPathUtils.newMapPath
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
Definition: MapPathUtils.java:43
net.sf.gridarta.model.mapmodel.MapPathUtils
Utility class for MapPath related functions.
Definition: MapPathUtils.java:28
net
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final File file)
Returns a MapFile instance for a File.
Definition: PathManager.java:84
net.sf.gridarta.utils.PathManagerUtils.getMapPath
static String getMapPath(@NotNull final File file, @NotNull final File baseDir)
Returns a relative path path for a File.
Definition: PathManagerUtils.java:58
net.sf.gridarta.model.io.PathManager.getMapPath
String getMapPath(@NotNull final File file)
Returns a map path for a File.
Definition: PathManager.java:62
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Definition: PathManager.java:72
net.sf.gridarta.model.io.PathManager.projectSettings
final ProjectSettings projectSettings
The ProjectSettings instance for obtaining folder information.
Definition: PathManager.java:45
net.sf.gridarta.model.io.PathManager.PathManager
PathManager(@NotNull final ProjectSettings projectSettings)
Creates a new instance.
Definition: PathManager.java:52
net.sf.gridarta.utils.PathManagerUtils
Utility class for converting relative map paths to absolute map paths and vice versa.
Definition: PathManagerUtils.java:31
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.model.settings.ProjectSettings
Settings that apply to a project.
Definition: ProjectSettings.java:29
net.sf.gridarta.model
net.sf.gridarta.utils.IOUtils
Utility-class for Gridarta's I/O.
Definition: IOUtils.java:40
net.sf.gridarta.model.settings.ProjectSettings.getMapsDirectory
File getMapsDirectory()
Returns the default maps directory.
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.utils.IOUtils.getCanonicalPath
static String getCanonicalPath(@NotNull final File file)
Calls File#getCanonicalPath().
Definition: IOUtils.java:192
net.sf.gridarta.model.settings
Definition: AbstractDefaultProjectSettings.java:20