Skip to content

Commit 2854491

Browse files
committed
Version 1.1
Adds Preference Support for replacing the Nexus Game Mods Path with a custom Nexus Mods URL SubPath Right Click Context Menu added to Profiles with Options to Change said path and open Profile Directory
1 parent ba42647 commit 2854491

File tree

5 files changed

+162
-19
lines changed

5 files changed

+162
-19
lines changed

readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ These outputs will be generated for each mod in the profile's mod list. The use
4545
----
4646

4747
Download: https://github.com/Rafael09ED/NMMModProfileExporter/releases
48+
49+
### Version History
50+
**1.0 - Initial Release**
51+
**1.1 - Custom Nexus URL Sub Paths for games**

src/META-INF/MANIFEST.MF

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.github.rafael09ed.nMMModProfileExporter.UserInterface
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.github.rafael09ed.nMMModProfileExporter;
2+
3+
import java.io.*;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
/**
8+
* PreferencesIO.java
9+
*
10+
* @author Rafael
11+
* @version 1.0 3/19/2017
12+
*/
13+
public class PreferencesIO {
14+
private final static String PREFERENCES_FILE_PATH = new File(".").getAbsolutePath() + "\\NMMProfileExporterPreferences.txt";
15+
private final Map<String, String> gameToUrlPath = new HashMap<>();
16+
private final static String HEADER__GAME_TO_URL_PATH = "#GameToNexusURLS";
17+
18+
public PreferencesIO() {
19+
if (new File(PREFERENCES_FILE_PATH).exists())
20+
try (BufferedReader br = new BufferedReader(new FileReader(PREFERENCES_FILE_PATH))) {
21+
String line;
22+
while ((line = br.readLine()) != null) {
23+
switch (line.trim()) {
24+
case HEADER__GAME_TO_URL_PATH:
25+
while ((line = br.readLine()) != null && !line.trim().equals("")) {
26+
String[] vals = line.split(" ");
27+
if (vals.length >= 2)
28+
gameToUrlPath.put(vals[0], vals[1]);
29+
}
30+
break;
31+
}
32+
}
33+
} catch (FileNotFoundException e) {
34+
e.printStackTrace();
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
}
38+
else {
39+
gameToUrlPath.put("skyrimse", "skyrimspecialedition");
40+
}
41+
42+
}
43+
44+
public String getUrlFromGamePath(String gamePath) {
45+
return gameToUrlPath.get(gamePath.toLowerCase());
46+
}
47+
48+
public void setUrlForGamePath(String game, String url) {
49+
if (url.trim().equals(""))
50+
url = null;
51+
gameToUrlPath.put(game, url);
52+
}
53+
54+
public void saveToFile() {
55+
try (BufferedWriter bw = new BufferedWriter(new FileWriter(PREFERENCES_FILE_PATH))) {
56+
bw.write(HEADER__GAME_TO_URL_PATH);
57+
bw.newLine();
58+
59+
for (String key : gameToUrlPath.keySet()) {
60+
bw.write(key + " " + gameToUrlPath.get(key));
61+
bw.newLine();
62+
}
63+
bw.newLine();
64+
bw.flush();
65+
} catch (IOException e) {
66+
e.printStackTrace();
67+
}
68+
}
69+
}

src/com/github/rafael09ed/nMMModProfileExporter/TextOutputFormater.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TextOutputFormater {
2929
"Mod Version: " + MOD_VERSION + "\n\n",
3030
MARKDOWN_VALUE = "[" + MOD_NAME_SIMPLE + "](" + MOD_NEXUS_LINK + ")\n\n";
3131

32-
public static String makeTextOutput(String layout, ModProfile profile) {
32+
public static String makeTextOutput(String layout, ModProfile profile, PreferencesIO preferences) {
3333
//StringBuilder output = new StringBuilder();
3434
List<String> list = splitAroundRegex(layout, REGEX);
3535
return profile.getMods().parallelStream().map(mod -> {
@@ -50,7 +50,9 @@ public static String makeTextOutput(String layout, ModProfile profile) {
5050
output.append(mod.getModId());
5151
break;
5252
case MOD_NEXUS_LINK:
53-
output.append(mod.getModURL(profile.getGameName().replaceAll("\\s+", "")));
53+
String gameName = profile.getGameName().replaceAll("\\s+", "");
54+
String gameURL = preferences.getUrlFromGamePath(gameName);
55+
output.append(mod.getModURL((gameURL != null) ? gameURL : gameName));
5456
break;
5557
case MOD_VERSION:
5658
output.append(mod.getModVersion());

src/com/github/rafael09ed/nMMModProfileExporter/UserInterface.java

+82-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
package com.github.rafael09ed.nMMModProfileExporter;
22

33
import javafx.application.Application;
4+
import javafx.application.Platform;
5+
import javafx.geometry.Side;
46
import javafx.scene.Scene;
7+
import javafx.scene.control.*;
58
import javafx.scene.control.Button;
9+
import javafx.scene.control.Dialog;
610
import javafx.scene.control.Label;
11+
import javafx.scene.control.MenuItem;
712
import javafx.scene.control.ScrollPane;
813
import javafx.scene.control.TextArea;
914
import javafx.scene.control.TextField;
15+
import javafx.scene.input.MouseButton;
16+
import javafx.scene.layout.GridPane;
1017
import javafx.scene.layout.HBox;
1118
import javafx.scene.layout.Priority;
1219
import javafx.scene.layout.VBox;
1320
import javafx.stage.Stage;
21+
import javafx.util.Pair;
1422

1523
import java.awt.*;
1624
import java.awt.datatransfer.Clipboard;
1725
import java.awt.datatransfer.StringSelection;
26+
import java.io.File;
27+
import java.io.IOException;
1828
import java.util.List;
29+
import java.util.Optional;
1930

2031

2132
/**
22-
* EGR 283 B01
23-
* UserInterface.java
24-
* Purpose:
25-
*
2633
* @author Rafael
2734
* @version 1.0 2/16/2017
2835
*/
@@ -33,6 +40,7 @@ public class UserInterface extends Application {
3340
private final Button autoFindButton = new Button("Auto"), demoButton = new Button("Demo"),
3441
markdownButton = new Button("Markdown"), copyButton = new Button("Copy Mod List");
3542
private ModProfile activeModProfile;
43+
private final PreferencesIO preferences = new PreferencesIO();
3644

3745
public static void main(String[] args) {
3846
launch(args);
@@ -94,7 +102,8 @@ public void start(Stage primaryStage) throws Exception {
94102
primaryStage.setScene(new Scene(main, 900, 800));
95103
primaryStage.getScene().getStylesheets().add("style.css");
96104

97-
primaryStage.setTitle("Nexus Mod Manager Mod Profile Extractor");
105+
primaryStage.setTitle("Nexus Mod Manager Mod Profile Extractor By Rafael09ED");
106+
primaryStage.setOnCloseRequest(event -> preferences.saveToFile());
98107
primaryStage.show();
99108
}
100109

@@ -106,7 +115,8 @@ private void updateList() {
106115
modListArea.setText(TextOutputFormater
107116
.makeTextOutput(
108117
layoutArea.getText(),
109-
activeModProfile
118+
activeModProfile,
119+
preferences
110120
));
111121
}
112122

@@ -115,32 +125,87 @@ private void loadProfiles(List<ModProfile> profiles) {
115125
if (profiles.size() > 0)
116126
activeModProfile = profiles.get(0);
117127
for (ModProfile profile : profiles) {
118-
VBox vBox = new VBox();
119-
vBox.setOnMouseClicked(event -> {
120-
activeModProfile = profile;
121-
updateList();
128+
VBox modProfileVBox = new VBox();
129+
modProfileVBox.setOnMouseClicked(event -> {
130+
if (event.getButton() == MouseButton.PRIMARY) {
131+
activeModProfile = profile;
132+
updateList();
133+
} else {
134+
ContextMenu modProfileContextMenu = new ContextMenu();
135+
MenuItem modProfileMenuItem = new MenuItem("Set URL Subpath for Game");
136+
modProfileMenuItem.setOnAction(e -> {
137+
Dialog<Pair<String, String>> dialog = new Dialog<>();
138+
dialog.setTitle("Set URL Subpath for Game");
139+
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL);
140+
141+
GridPane grid = new GridPane();
142+
143+
TextField gameField = new TextField();
144+
gameField.setPromptText("Game Path");
145+
gameField.setText(profile.getGameName().toLowerCase());
146+
TextField urlField = new TextField();
147+
urlField.setPromptText("Nexus Mod URL SubPath");
148+
grid.add(new Label("Game Path:"), 0, 0);
149+
grid.add(gameField, 0, 1);
150+
grid.add(new Label("URL Path:"), 1, 0);
151+
grid.add(urlField, 1, 1);
152+
153+
dialog.getDialogPane().setContent(grid);
154+
Platform.runLater(urlField::requestFocus);
155+
dialog.setResultConverter(dialogButton -> {
156+
if (dialogButton == ButtonType.APPLY) {
157+
return new Pair<>(gameField.getText(), urlField.getText());
158+
}
159+
return null;
160+
});
161+
162+
Optional<Pair<String, String>> result = dialog.showAndWait();
163+
result.ifPresent(values -> {
164+
preferences.setUrlForGamePath(values.getKey(), values.getValue());
165+
updateList();
166+
});
167+
});
168+
modProfileContextMenu.getItems().add(modProfileMenuItem);
169+
170+
modProfileMenuItem = new MenuItem("Open Profile Path");
171+
modProfileMenuItem.setOnAction(e -> {
172+
try {
173+
Desktop.getDesktop().open(new File(profile.getProfilePath()));
174+
} catch (IOException e1) {
175+
Alert alert = new Alert(Alert.AlertType.ERROR);
176+
alert.setTitle("Error");
177+
alert.setHeaderText(null);
178+
alert.setContentText("Could Not Open Path");
179+
alert.show();
180+
}
181+
});
182+
modProfileContextMenu.getItems().add(modProfileMenuItem);
183+
184+
modProfileContextMenu.show(modProfileVBox, Side.BOTTOM, 0, 0);
185+
}
122186
});
187+
123188
Label label;
124189

125190
String profileName = profile.getProfileName();
126191
if (profileName == null || profileName.trim().length() <= 0)
127192
profileName = "Untitled Profile";
128193
label = new Label(profileName);
129194
label.getStyleClass().add("profileTitle");
130-
vBox.getChildren().add(label);
195+
modProfileVBox.getChildren().add(label);
131196

132197
label = new Label(profile.getGameName());
133-
vBox.getChildren().add(label);
198+
modProfileVBox.getChildren().add(label);
134199

135200
label = new Label(profile.getProfilePath());
136-
vBox.getChildren().add(label);
201+
modProfileVBox.getChildren().add(label);
137202

138203
label = new Label(profile.getMods().size() + " Mods");
139-
vBox.getChildren().add(label);
204+
modProfileVBox.getChildren().add(label);
140205

141-
vBox.getStyleClass().add("profileListItem");
142-
vBox.setMaxWidth(Double.MAX_VALUE);
143-
modProfilesList.getChildren().add(vBox);
206+
modProfileVBox.getStyleClass().add("profileListItem");
207+
modProfileVBox.setMaxWidth(Double.MAX_VALUE);
208+
modProfilesList.getChildren().add(modProfileVBox);
144209
}
145210
updateList();
146211
}

0 commit comments

Comments
 (0)