• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 194

pending completion
194

push

circleci

Eliminate stacktrace when compiling on linux (#1076)

* Eliminate stacktrace when compiling on linux

* catch unsupported platform at exe path

17138 of 27014 relevant lines covered (63.44%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/utils/W3InstallationData.java
1
package de.peeeq.wurstio.utils;
2

3
import de.peeeq.wurstscript.WLogger;
4
import net.moonlightflower.wc3libs.bin.GameExe;
5
import net.moonlightflower.wc3libs.port.GameVersion;
6
import net.moonlightflower.wc3libs.port.NotFoundException;
7
import net.moonlightflower.wc3libs.port.Orient;
8
import net.moonlightflower.wc3libs.port.StdGameExeFinder;
9
import net.moonlightflower.wc3libs.port.StdGameVersionFinder;
10
import net.moonlightflower.wc3libs.port.UnsupportedPlatformException;
11
import net.moonlightflower.wc3libs.port.win.WinGameExeFinder;
12

13
import java.io.File;
14
import java.io.IOException;
15
import java.util.Optional;
16

17
public class W3InstallationData {
18
    private Optional<File> gameExe = Optional.empty();
×
19

20
    private Optional<GameVersion> version = Optional.empty();
×
21

22
    public W3InstallationData(Optional<File> gameExe, Optional<GameVersion> version) {
×
23
        this.gameExe = gameExe;
×
24
        this.version = version;
×
25
    }
×
26

27
    /** Evaluates the game path and version by discovering the system environment. */
28
    public W3InstallationData() {
×
29
        discoverExePath();
×
30
        discoverVersion();
×
31
    }
×
32

33
    /**
34
     * Evaluates the game path and version, attempting to use the provided path if possible, before discovering the
35
     * system environment.
36
     */
37
    public W3InstallationData(File wc3Path) {
×
38
        if (!Orient.isWindowsSystem()) {
×
39
            WLogger.warning("Game path configuration only works on windows");
×
40
            discoverExePath();
×
41
            discoverVersion();
×
42
            return;
×
43
        }
44

45
        try {
46
            gameExe = Optional.ofNullable(WinGameExeFinder.fromDirIgnoreVersion(wc3Path));
×
47
        } catch (NotFoundException e) {
×
48
            WLogger.severe(e);
×
49
        }
×
50
        WLogger.info("Game Executable from path: " + gameExe);
×
51

52
        version = gameExe.flatMap(exe -> {
×
53
            try {
54
                return Optional.ofNullable(GameExe.getVersion(exe));
×
55
            } catch (IOException e) {
×
56
                WLogger.severe(e);
×
57
            }
58

59
            return Optional.empty();
×
60
        });
61
        WLogger.info("Parsed custom game version from executable: " + version);
×
62

63
        if (!gameExe.isPresent()) {
×
64
            WLogger.warning("The provided wc3 path wasn't suitable. Falling back to discovery.");
×
65
            discoverExePath();
×
66
            discoverVersion();
×
67
        }
68
    }
×
69

70
    private void discoverExePath() {
71
        try {
72
            gameExe = Optional.ofNullable(new StdGameExeFinder().get());
×
73
            WLogger.info("Parsed game path: " + gameExe);
×
74
        } catch (NotFoundException e) {
×
75
            e.printStackTrace();
×
76
        } catch (UnsupportedPlatformException e) {
×
77
            WLogger.warning("Wurst compiler cannot determine game path: " + e.getMessage());
×
78
        }
×
79
    }
×
80

81
    private void discoverVersion() {
82
        try {
83
            version = Optional.ofNullable(new StdGameVersionFinder().get());
×
84
            WLogger.info("Parsed game version: " + version);
×
85
        } catch (NotFoundException e) {
×
86
            WLogger.warning("Wurst compiler failed to determine game version", e);
×
87
        } catch (UnsupportedPlatformException e) {
×
88
            WLogger.warning("Wurst compiler cannot determine game version: " + e.getMessage());
×
89
        }
×
90
    }
×
91

92
    /**
93
     * @return The wc3 patch version or empty if none has been found
94
     */
95
    public Optional<GameVersion> getWc3PatchVersion() {
96
        return version;
×
97
    }
98

99
    /**
100
     * @return The wc3 path or empty if none has been found
101
     */
102
    public Optional<File> getGameExe() {
103
        return gameExe;
×
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc