Skip to content

Commit

Permalink
intermediate: ImagePath revision
Browse files Browse the repository at this point in the history
  • Loading branch information
RaiMan committed Mar 1, 2021
1 parent 039b500 commit c6908f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
38 changes: 16 additions & 22 deletions API/src/main/java/org/sikuli/script/ImagePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public boolean equals(Object other) {
public String toString() {
return getPath();
}

public boolean isValid() {
return pathURL != null;
}
Expand Down Expand Up @@ -436,34 +437,27 @@ public static boolean addHTTP(String pathHTTP) {
}

private static URL makeNetURL(String pathHTTP) {
URL url = null;
try {
String proto = "http://";
String protos = "https://";
if (!pathHTTP.startsWith(proto) && !pathHTTP.startsWith(protos)) {
pathHTTP = proto + pathHTTP;
}

url = new URL(pathHTTP);
} catch (MalformedURLException e) {
log(-1, "addHTTP: invalid: %s (%s)", pathHTTP, e);
String proto = "http://";
String protos = "https://";
if (!pathHTTP.startsWith(proto) && !pathHTTP.startsWith(protos)) {
pathHTTP = proto + pathHTTP;
}
return url;
return Commons.makeURL(pathHTTP);
}

public static boolean removeHTTP(String pathHTTP) {
return null != remove(makeNetURL(pathHTTP));
}

public static boolean addJar(String fpJar) {
return removeJar(fpJar, null);
return addJar(fpJar, null);
}

public static boolean addJar(String fpJar, String fpImage) {
if (!fpJar.endsWith(".jar") && !fpJar.contains(".jar!")) {
fpJar += ".jar";
}
return remove(fpJar, fpImage);
return null != append(fpJar, fpImage);
}

public static boolean removeJar(String fpJar) {
Expand Down Expand Up @@ -667,13 +661,16 @@ private static void setBundle(PathEntry pathEntry) {
//</editor-fold>

//<editor-fold desc="10 find image">
public static URL check(String name) {
return find(Image.getValidImageFilename(name));
}

/**
* try to find the given relative image file name on the image path<br>
* starting from entry 0, the first found existence is taken<br>
* absolute file names are checked for existence
*
* @param imageFileName relative or absolute filename
* @param imageFileName relative or absolute filename with extension
* @return a valid URL or null if not found/exists
*/
public static URL find(String imageFileName) {
Expand All @@ -695,7 +692,7 @@ public static URL find(String imageFileName) {
proto = entry.pathURL.getProtocol();
if ("file".equals(proto)) {
if (new File(entry.getPath(), imageFileName).exists()) {
fURL = Commons.makeURL(entry.getPath(), imageFileName);
return Commons.makeURL(entry.getPath(), imageFileName);
}
} else if ("jar".equals(proto) || proto.startsWith("http")) {
URL url = Commons.makeURL(entry.getPath(), imageFileName);
Expand All @@ -711,16 +708,13 @@ public static URL find(String imageFileName) {
}
}
if (check > 0) {
fURL = url;
break;
return url;
}
}
}
}
if (fURL == null) {
log(-1, "find: not there: %s", imageFileName);
dump(lvl);
}
log(-1, "find: not there: %s", imageFileName);
dump(lvl);
return fURL;
}
}
Expand Down
19 changes: 7 additions & 12 deletions API/src/main/resources/Lib/sikuli/Sikuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,8 @@ def addImagePath(*args):
return ImagePath.append(args[0], args[1])
return None

def addHTTPImagePath(*args):
if (len(args) == 1):
return ImagePath.addHTTP(args[0])
elif (len(args) == 2):
return ImagePath.addHTTP(args[0], args[1])
return None
def addHTTPImagePath(arg):
return ImagePath.addHTTP(arg)

def addJarImagePath(*args):
if (len(args) == 1):
Expand All @@ -289,12 +285,8 @@ def removeImagePath(*args):
return ImagePath.remove(args[0], args[1])
return None

def removeHTTPImagePath(*args):
if (len(args) == 1):
return ImagePath.removeHTTP(args[0])
elif (len(args) == 2):
return ImagePath.removeHTTP(args[0], args[1])
return None
def removeHTTPImagePath(arg):
return ImagePath.removeHTTP(arg)

def removeJarImagePath(*args):
if (len(args) == 1):
Expand All @@ -315,6 +307,9 @@ def getImagePath():
def resetImagePath(path=None):
ImagePath.reset(path)

def checkImage(image):
return ImagePath.check(image)

## ----------------------------------------------------------------------
# Sets the path for searching images in all Sikuli Script methods. <br/>
# Sikuli IDE sets this to the path of the bundle of source code (.sikuli)
Expand Down

0 comments on commit c6908f3

Please sign in to comment.