Skip to content

Commit 6fb50d5

Browse files
committed
Add directory path normalization
1 parent 2cc8d2d commit 6fb50d5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/com/joelchristophel/sourceradio/FileUtilities.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,11 @@ static boolean removeLine(String path, String line, boolean commentAware) {
167167
}
168168
return hasLine;
169169
}
170+
171+
static String normalizeDirectoryPath(String path) {
172+
if (path != null && !path.endsWith(File.separator)) {
173+
path += File.separator;
174+
}
175+
return path;
176+
}
170177
}

src/com/joelchristophel/sourceradio/Properties.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ String get(String key) {
113113

114114
Player getOwner() throws FileNotFoundException {
115115
if (owner == null) {
116-
String steamPath = properties.get("steam path") + File.separator;
116+
String steamPath = FileUtilities.normalizeDirectoryPath(properties.get("steam path"));
117117
if (!new File(steamPath).exists()) {
118118
throw new FileNotFoundException("Error: Could not find a Steam installation. "
119119
+ "Check your Steam path in properties/properties.txt");
@@ -153,14 +153,15 @@ Player getOwner() throws FileNotFoundException {
153153
private File getUserDirectory(String steamPath) throws FileNotFoundException {
154154
File userdata = new File(steamPath + "userdata");
155155
if (!userdata.exists()) {
156-
throw new FileNotFoundException("Error: Could not find Steam userdata directory: " + userdata.getAbsolutePath());
156+
throw new FileNotFoundException(
157+
"Error: Could not find Steam userdata directory: " + userdata.getAbsolutePath());
157158
}
158159
List<File> users = Arrays.asList(userdata.listFiles());
159160
for (Iterator<File> iterator = users.iterator(); iterator.hasNext();) {
160-
File user = iterator.next();
161-
if (!user.getName().matches("[0-9]+")) {
162-
iterator.remove();
163-
}
161+
File user = iterator.next();
162+
if (!user.getName().matches("[0-9]+")) {
163+
iterator.remove();
164+
}
164165
}
165166
File userDirectory = users.get(0); // May be wrong account
166167
String steamId3 = properties.get("steamid3");
@@ -174,7 +175,7 @@ private File getUserDirectory(String steamPath) throws FileNotFoundException {
174175
}
175176
return userDirectory;
176177
}
177-
178+
178179
/**
179180
* Returns a set containing each admin listed in the <code>admins</code> file.
180181
*

0 commit comments

Comments
 (0)