Skip to content

Commit 7b0092f

Browse files
committed
Re-commit files
1 parent 0295066 commit 7b0092f

15 files changed

Lines changed: 987 additions & 13 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,5 @@ dmypy.json
250250
# Cython debug symbols
251251
cython_debug/
252252

253+
!/DLSS/
254+
!/Game_List.TXT

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/ModelPythonBackup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import zipfile
2+
from sys import argv
3+
4+
5+
def main(dir_list_str: str) -> str:
6+
7+
dir_list_split: list = dir_list_str.split(">")
8+
9+
game_dlss_dir: str = dir_list_split[0]
10+
backup_file_name: str = dir_list_split[1] + dir_list_split[2] + ".zip"
11+
12+
with zipfile.ZipFile(backup_file_name, "w", compression=zipfile.ZIP_LZMA, compresslevel=9) as backup_zip:
13+
backup_zip.write(game_dlss_dir, arcname="nvngx_dlss.dll")
14+
15+
return str(True)
16+
17+
18+
if __name__ == "__main__":
19+
20+
result: str = main(argv[1])
21+
print(result)

Python/ModelPythonReplace.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import zipfile
2+
from sys import argv
3+
from os import remove
4+
5+
6+
def main(game_dlss_dir: str, replace_dlss_file_dir: str) -> str:
7+
8+
remove(game_dlss_dir)
9+
10+
game_dlss_dir_split: list = game_dlss_dir.split("\\")
11+
game_dlss_dir = ""
12+
13+
for i in range(len(game_dlss_dir_split) - 1):
14+
15+
game_dlss_dir += game_dlss_dir_split[i]
16+
17+
if i < len(game_dlss_dir_split) - 1:
18+
game_dlss_dir += "\\"
19+
20+
with zipfile.ZipFile(replace_dlss_file_dir, "r") as dlss_zip_file:
21+
dlss_zip_file.extractall(game_dlss_dir)
22+
23+
return str(True)
24+
25+
26+
if __name__ == "__main__":
27+
28+
result: str = main(argv[1], argv[2])
29+
print(result)

Python/ModelPythonSearch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ def main(dlss_dir: str) -> str:
2020

2121
result: str = main(argv[1])
2222
print(result)
23-

Supersede.iml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="Python" name="Python">
5+
<configuration sdkName="Python 3.10 (Supercede)" />
6+
</facet>
7+
</component>
38
<component name="NewModuleRootManager" inherit-compiler-output="true">
49
<exclude-output />
510
<content url="file://$MODULE_DIR$">
611
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
12+
<excludeFolder url="file://$MODULE_DIR$/venv" />
713
</content>
814
<orderEntry type="inheritedJdk" />
915
<orderEntry type="sourceFolder" forTests="false" />
16+
<orderEntry type="library" name="Python 3.10 (Supercede) interpreter library" level="application" />
1017
</component>
1118
</module>

src/GUI/ViewUserInterface.form

Lines changed: 276 additions & 3 deletions
Large diffs are not rendered by default.

src/GUI/ViewUserInterface.java

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,166 @@
1-
package GUI;public class ViewUserInterface {
1+
package GUI;
2+
3+
import History.ControllerBackup;
4+
import Replace.ControllerReplace;
5+
import Search.ControllerSearch;
6+
7+
import javax.swing.*;
8+
import java.awt.*;
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.net.URI;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.util.Objects;
15+
import java.util.concurrent.ExecutorService;
16+
import java.util.concurrent.Executors;
17+
18+
public class ViewUserInterface extends JFrame {
19+
20+
private JPanel panelMain;
21+
private JLabel labelRequiredAction;
22+
private JButton buttonDLSSWebsite;
23+
private JButton buttonAddGameDirectory;
24+
private JLabel labelRestoreBackup;
25+
private JButton buttonRestoreBackup;
26+
private JLabel labelGitHubLink;
27+
private JButton buttonReplaceDLSS;
28+
private JLabel labelProgress;
29+
private JLabel labelProgressUpdate;
30+
31+
private ExecutorService controllerService;
32+
public static boolean isControllerRunning;
33+
34+
public ViewUserInterface() {
35+
36+
SwingUtilities.invokeLater(this::initUserInterface);
37+
SwingUtilities.invokeLater(this::initNonUserInterface);
38+
39+
buttonDLSSWebsite.addActionListener(e -> {
40+
41+
try {
42+
Desktop desktop = Desktop.getDesktop();
43+
desktop.browse(URI.create("https://www.techpowerup.com/download/nvidia-dlss-dll/"));
44+
} catch (IOException ex) { throw new RuntimeException(ex); }
45+
46+
});
47+
48+
buttonAddGameDirectory.addActionListener(e -> {
49+
50+
if (isControllerRunning) return;
51+
52+
File gameRootDir = null;
53+
54+
JFileChooser dirChooser = new JFileChooser();
55+
dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
56+
dirChooser.setDialogTitle("Select Game Root Directory");
57+
58+
int dirChoice = dirChooser.showDialog(this, "Select");
59+
60+
if (dirChoice == JFileChooser.APPROVE_OPTION) gameRootDir = dirChooser.getSelectedFile();
61+
62+
if (gameRootDir != null) responseButtonAddGameDirectory(gameRootDir);
63+
64+
});
65+
66+
buttonReplaceDLSS.addActionListener(e -> {
67+
68+
if (isControllerRunning) return;
69+
70+
File[] DLSSDir = new File("DLSS").listFiles();
71+
72+
if (DLSSDir == null || DLSSDir.length == 0) {
73+
74+
showMessage("DLSS directory is empty!");
75+
return;
76+
77+
}
78+
79+
ControllerBackup controllerBackup = new ControllerBackup(this);
80+
ControllerReplace controllerReplace = new ControllerReplace(this, false);
81+
this.controllerService.submit(controllerBackup);
82+
this.controllerService.submit(controllerReplace);
83+
84+
});
85+
86+
buttonRestoreBackup.addActionListener(e -> {
87+
88+
if (isControllerRunning) return;
89+
90+
File[] backupDir = new File("Backup").listFiles();
91+
92+
if (backupDir == null || backupDir.length == 0) {
93+
94+
showMessage("Backup directory is empty!");
95+
return;
96+
97+
}
98+
99+
ControllerReplace controllerReplace = new ControllerReplace(this, true);
100+
this.controllerService.submit(controllerReplace);
101+
102+
});
103+
104+
}
105+
106+
private void responseButtonAddGameDirectory(File gameRootDir) {
107+
108+
ControllerSearch controllerSearch = new ControllerSearch(this, gameRootDir);
109+
this.controllerService.submit(controllerSearch);
110+
111+
}
112+
113+
private void showMessage(String text) {
114+
115+
SwingUtilities.invokeLater(() ->
116+
JOptionPane.showMessageDialog(this, text, "Warning", JOptionPane.WARNING_MESSAGE));
117+
}
118+
119+
public void updateLabelProgressUpdate(String progressText) {
120+
121+
SwingUtilities.invokeLater(() -> labelProgressUpdate.setText(progressText));
122+
123+
}
124+
125+
private void initUserInterface() {
126+
127+
this.labelRequiredAction.setText("Required User Action");
128+
this.buttonDLSSWebsite.setText("Download DLSS");
129+
this.buttonAddGameDirectory.setText("Add Game Directory");
130+
131+
this.labelRestoreBackup.setText("Restore");
132+
this.buttonRestoreBackup.setText("Restore Backup");
133+
134+
this.labelGitHubLink.setText("https://github.com/YorkshireDev");
135+
this.buttonReplaceDLSS.setText("Replace DLSS");
136+
this.labelProgress.setText("Progress");
137+
this.labelProgressUpdate.setText("N/A");
138+
139+
this.setContentPane(panelMain);
140+
this.setTitle("Supersede");
141+
this.setPreferredSize(new Dimension(480, 240));
142+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
143+
this.setLocationRelativeTo(null);
144+
this.pack();
145+
this.setVisible(true);
146+
147+
}
148+
149+
private void initNonUserInterface() {
150+
151+
Path dlssFolderPath = Path.of("DLSS");
152+
Path dlssValidGameFilePath = Path.of("Game_List.TXT");
153+
154+
try {
155+
156+
if (! Files.exists(dlssFolderPath)) Files.createDirectory(dlssFolderPath);
157+
if (! Files.exists(dlssValidGameFilePath)) Files.createFile(dlssValidGameFilePath);
158+
159+
} catch (IOException e) { throw new RuntimeException(e); }
160+
161+
this.controllerService = Executors.newSingleThreadExecutor();
162+
isControllerRunning = false;
163+
164+
}
165+
2166
}

src/History/ControllerBackup.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
package History;public class ControllerBackup {
1+
package History;
2+
3+
import GUI.ViewUserInterface;
4+
5+
import java.io.BufferedReader;
6+
import java.io.FileReader;
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
import java.util.concurrent.CountDownLatch;
14+
import java.util.concurrent.ExecutorService;
15+
import java.util.concurrent.Executors;
16+
17+
public class ControllerBackup implements Runnable {
18+
19+
private final ViewUserInterface viewUserInterface;
20+
21+
private final ExecutorService modelBackupService;
22+
static CountDownLatch modelBackupLatch;
23+
24+
public ControllerBackup(ViewUserInterface viewUserInterface) {
25+
26+
this.viewUserInterface = viewUserInterface;
27+
this.modelBackupService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
28+
29+
}
30+
31+
@Override
32+
public void run() {
33+
34+
ViewUserInterface.isControllerRunning = true;
35+
36+
try {
37+
38+
Path backupPath = Path.of("Backup");
39+
if (! Files.exists(backupPath)) Files.createDirectory(backupPath);
40+
41+
List<ModelBackup> modelBackupList = new ArrayList<>();
42+
43+
BufferedReader gameListReader = new BufferedReader(new FileReader("Game_List.TXT"));
44+
String gameLine;
45+
46+
while ((gameLine = gameListReader.readLine()) != null) modelBackupList.add(new ModelBackup(gameLine));
47+
48+
Collections.shuffle(modelBackupList);
49+
50+
int gameAmount = modelBackupList.size();
51+
modelBackupLatch = new CountDownLatch(gameAmount);
52+
53+
for (ModelBackup modelBackup : modelBackupList) this.modelBackupService.submit(modelBackup);
54+
55+
while (modelBackupLatch.getCount() > 0) {
56+
57+
long searchedDirs = gameAmount - modelBackupLatch.getCount();
58+
String progressText = searchedDirs + "/" + gameAmount;
59+
viewUserInterface.updateLabelProgressUpdate(progressText);
60+
61+
try {
62+
Thread.sleep(1L);
63+
} catch (InterruptedException e) { throw new RuntimeException(e); }
64+
65+
}
66+
67+
viewUserInterface.updateLabelProgressUpdate("Done!");
68+
69+
} catch (IOException e) { throw new RuntimeException(e); }
70+
71+
ViewUserInterface.isControllerRunning = false;
72+
73+
}
74+
275
}

0 commit comments

Comments
 (0)