Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyPavlenko committed May 30, 2021
1 parent 65ee86c commit f998d29
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 329 deletions.
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def version = '1.3.7'
def versionNum = 9000013
def versionNum = 9000015
def webInstallDir = "${project.buildDir}/web"

buildscript {
repositories {
Expand Down Expand Up @@ -33,7 +34,7 @@ android {

externalNativeBuild.cmake {
targets 'transmissionbtc'
arguments "-DTR_SRC_DIR=${project.buildDir}/transmission"
arguments "-DTR_SRC_DIR=${project.buildDir}/transmission", "-DTR_WEB_INSTALL_DIR=${webInstallDir}"
}

ndk {
Expand Down Expand Up @@ -87,7 +88,8 @@ android {
}

applicationVariants.all { v ->
tasks["merge${v.name.capitalize()}Assets"].dependsOn(generateAssets)
tasks["merge${v.name.capitalize()}Assets"].dependsOn("mergeWebAssets${v.name.capitalize()}")
tasks["mergeWebAssets${v.name.capitalize()}"].dependsOn("externalNativeBuild${v.name.capitalize()}")
}

lintOptions {
Expand All @@ -108,7 +110,7 @@ task cleanAll(type: Delete) {
delete file(".cxx")
}

task generateAssets() {
task mergeWebAssets() {
doLast {
def webDir = "${project.buildDir}/assets/web"
def arch = file("${project.buildDir}/web-control.tar.gz")
Expand All @@ -119,9 +121,8 @@ task generateAssets() {
}

copy {
from "${project.buildDir}/transmission/web"
from "${webInstallDir}/usr/local/share/transmission/public_html"
into webDir
exclude '*.am', '*.in', '*.scss'
}

copy {
Expand All @@ -145,3 +146,9 @@ task generateAssets() {
}
}
}

task mergeWebAssetsRelease(dependsOn: mergeWebAssets) {
}

task mergeWebAssetsDebug(dependsOn: mergeWebAssets) {
}
4 changes: 2 additions & 2 deletions cmake/Transmission.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option(TR_SRC_DIR "Transmission sources" "${CMAKE_CURRENT_BINARY_DIR}/transmissi
set(TR_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/transmission/src/transmission-build")
set(TR_CMAKE_ARGS -DENABLE_TESTS=OFF -DENABLE_DAEMON=OFF -DINSTALL_DOC=OFF -DENABLE_UTILS=OFF
-DENABLE_CLI=OFF -DENABLE_GTK=OFF -DENABLE_QT=OFF -DENABLE_MAC=OFF -DINSTALL_DOC=OFF
${EXT_CMAKE_ARGS})
-DENABLE_WEB=ON ${EXT_CMAKE_ARGS})

set(TR_LIBRARIES
"${TR_BUILD_DIR}/libtransmission/libtransmission.a"
Expand All @@ -31,7 +31,7 @@ ExternalProject_Add(transmission
GIT_SUBMODULES_RECURSE 1
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${TR_SRC_DIR} ${TR_CMAKE_ARGS}
BUILD_COMMAND ${MAKE_EXE} -j${NCPU}
INSTALL_COMMAND echo "Skip install"
INSTALL_COMMAND ${MAKE_EXE} install "DESTDIR=${TR_WEB_INSTALL_DIR}"
BUILD_BYPRODUCTS ${TR_LIBRARIES})

add_dependencies(transmission openssl curl libevent)
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/com/ap/transmission/btc/BindingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public boolean and(boolean... bools) {
return true;
}

public boolean isPro() {
return Utils.isPro();
}

public boolean isBasic() {
return Utils.isBasic();
}

public String getIp() {
return Utils.getIPAddress(getActivity());
}
Expand All @@ -70,16 +62,13 @@ public boolean isSuspended() {
public void startStopService(final View... disable) {
final boolean running = isServiceRunning();
for (View v : disable) v.setEnabled(false);
Runnable callback = new Runnable() {
@Override
public void run() {
for (View v : disable) v.setEnabled(true);
isServiceRunning = TransmissionService.isRunning() ? (byte) 1 : 0;
invalidate();

if (!running && !isServiceRunning()) {
Utils.showErr(disable[0], R.string.err_failed_to_start_transmission);
}
Runnable callback = () -> {
for (View v : disable) v.setEnabled(true);
isServiceRunning = TransmissionService.isRunning() ? (byte) 1 : 0;
invalidate();

if (!running && !isServiceRunning()) {
Utils.showErr(disable[0], R.string.err_failed_to_start_transmission);
}
};

Expand Down
49 changes: 11 additions & 38 deletions src/main/java/com/ap/transmission/btc/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.ap.transmission.btc.func.Function;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -27,7 +26,6 @@
import static com.ap.transmission.btc.Prefs.K.ENABLE_UPNP;
import static com.ap.transmission.btc.Prefs.K.ENABLE_WATCH_DIR;
import static com.ap.transmission.btc.Prefs.K.ENCR_MODE;
import static com.ap.transmission.btc.Prefs.K.FOREGROUND;
import static com.ap.transmission.btc.Prefs.K.HTTP_SERVER_PORT;
import static com.ap.transmission.btc.Prefs.K.INCREASE_SO_BUF;
import static com.ap.transmission.btc.Prefs.K.RPC_PASSWD;
Expand All @@ -47,18 +45,10 @@
*/
public class Prefs {
public enum K {
SETTINGS_DIR(new Function<Prefs, Object>() {
public Object apply(Prefs p) { return p.getDefaultSettingsDir(); }
}),
DOWNLOAD_DIR(new Function<Prefs, Object>() {
public Object apply(Prefs p) { return p.getDefaultDownloadDir(); }
}),
PREV_DOWNLOAD_DIR(new Function<Prefs, Object>() {
public Object apply(Prefs p) { return p.getDownloadDir(); }
}),
WATCH_DIR(new Function<Prefs, Object>() {
public Object apply(Prefs p) { return p.getDefaultWatchDir(); }
}),
SETTINGS_DIR(Prefs::getDefaultSettingsDir),
DOWNLOAD_DIR(Prefs::getDefaultDownloadDir),
PREV_DOWNLOAD_DIR(Prefs::getDownloadDir),
WATCH_DIR(Prefs::getDefaultWatchDir),
START_ON_BOOT(false),
BOOT_DELAY(0),
ENABLE_WATCH_DIR(false),
Expand All @@ -83,7 +73,6 @@ public enum K {
HTTP_SERVER_PORT(9092),
WIFI_ETH_ONLY(true),
WIFI_SSID(""),
FOREGROUND(true),
UUID(new Function<Prefs, Object>() {
public Object apply(Prefs p) {
String uuid = java.util.UUID.randomUUID().toString();
Expand Down Expand Up @@ -198,8 +187,6 @@ private Object getObject(K k) {
return isWifiEthOnly();
case WIFI_SSID:
return getWifiSsid();
case FOREGROUND:
return isForeground();
default:
return getString(k);
}
Expand Down Expand Up @@ -269,7 +256,7 @@ public void set(K k, Object value) {
setSeqDownloadEnabled((Boolean) value);
break;
case ENABLE_UPNP:
setUpnpEnabled(Boolean.valueOf(value.toString()));
setUpnpEnabled(Boolean.parseBoolean(value.toString()));
break;
case HTTP_SERVER_PORT:
setHttpServerPort(value.toString());
Expand All @@ -280,9 +267,6 @@ public void set(K k, Object value) {
case WIFI_SSID:
setWifiSsid(value.toString());
break;
case FOREGROUND:
setForeground((Boolean) value);
break;
default:
putString(k, value.toString());
}
Expand Down Expand Up @@ -334,11 +318,7 @@ public void setDownloadDir(CharSequence dir) {
}

public boolean isWatchDirEnabled() {
if (Utils.isBasic()) {
return getBoolean(ENABLE_WATCH_DIR);
} else {
return prefs.getString(K.WATCH_DIR.id(0), null) != null;
}
return prefs.getString(K.WATCH_DIR.id(0), null) != null;
}

public void setWatchDirEnabled(boolean enabled) {
Expand Down Expand Up @@ -367,7 +347,6 @@ private String getDefaultWatchDir() {


public Map<String, String> getWatchDirs() {
if (Utils.isBasic()) return Collections.singletonMap(getWatchDir(), getDownloadDir());
Map<String, String> m = new HashMap<>();

for (int i = 0; ; i++) {
Expand Down Expand Up @@ -551,21 +530,13 @@ public void setWifiSsid(CharSequence list) {
putString(WIFI_SSID, list.toString().trim());
}

public boolean isForeground() {
return getBoolean(FOREGROUND);
}

public void setForeground(boolean foreground) {
putBoolean(FOREGROUND, foreground);
}

public String getUUID() {
return getString(UUID);
}

public String getString(K k) {
String s = prefs.getString(k.id(), null);
return (s == null) || s.isEmpty() ? k.<String>def(this) : s;
return (s == null) || s.isEmpty() ? k.def(this) : s;
}

public String getString(K k, int index, String def) {
Expand Down Expand Up @@ -614,7 +585,8 @@ public int getInt(K k) {
public void putInt(K k, CharSequence value) {
try {
putInt(k, Integer.parseInt(value.toString()));
} catch (NumberFormatException ignore) {}
} catch (NumberFormatException ignore) {
}
}

public void putInt(K k, int value) {
Expand All @@ -638,7 +610,8 @@ private static File selectMaxSize(File[] files) {
if (f == null) continue;
StatFs stat = new StatFs(f.getAbsolutePath());
if (maxLen < stat.getTotalBytes()) max = f;
} catch (IllegalArgumentException ignore) {}
} catch (IllegalArgumentException ignore) {
}
}

return max;
Expand Down
34 changes: 6 additions & 28 deletions src/main/java/com/ap/transmission/btc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public class Utils {
public static final Charset UTF8 = Charset.forName("UTF-8");
private static final String TAG = Utils.class.getName();
@SuppressWarnings("ConstantConditions")
private static final boolean isPro = BUILD_TYPE.endsWith("pro");
private static final boolean isBasic = BUILD_TYPE.endsWith("basic");
private static final boolean isDebugEnabled = BUILD_TYPE.startsWith("debug");
private static volatile InetAddress ifaddr;

Expand Down Expand Up @@ -220,6 +218,8 @@ public static String getRealDirPath(Context ctx, Uri dirUri) {
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) return null;
ParcelFileDescriptor pfd = null;
DocumentFile dir = DocumentFile.fromTreeUri(ctx, dirUri);
if (dir == null) return null;

String rndName = "transmissionbtc-" + UUID.randomUUID() + ".tmp";
DocumentFile f = dir.createFile(StorageAccess.MIME_TYPE, rndName);

Expand Down Expand Up @@ -294,14 +294,6 @@ public static boolean hasWritePerms(File dir) {
}
}

public static boolean isPro() {
return isPro;
}

public static boolean isBasic() {
return isBasic;
}

public static boolean isDebugEnabled() {
return isDebugEnabled;
}
Expand Down Expand Up @@ -437,19 +429,11 @@ private static void copyAssets(AssetManager amgr, String src, File dstDir, byte[
File dst = new File(dstDir, src);
debug(TAG, "Copying assets %s -> %s", src, dst);
mkdirs(dst.getParentFile());
InputStream in = null;
OutputStream out = null;

try {
in = amgr.open(src);
out = new FileOutputStream(dst);

try (InputStream in = amgr.open(src); OutputStream out = new FileOutputStream(dst)) {
for (int i = in.read(buf); i != -1; i = in.read(buf)) {
out.write(buf, 0, i);
}
} finally {
if (in != null) in.close();
if (out != null) out.close();
}
}
}
Expand All @@ -474,15 +458,11 @@ public static int exec(long timeout, final InputStream script, List<String> cmd)
@Override
public void run() {
if (script != null) {
OutputStream out = p.getOutputStream();
byte[] buf = new byte[1024];

try {
try (OutputStream out = p.getOutputStream()) {
byte[] buf = new byte[1024];
for (int i = script.read(buf); i != -1; i = script.read(buf)) out.write(buf, 0, i);
} catch (IOException ex) {
Log.e(TAG, ex.getMessage(), ex);
} finally {
try { out.close(); } catch (IOException ignore) {}
}
}

Expand Down Expand Up @@ -516,9 +496,8 @@ public void run() {
}
}

@SuppressWarnings("unchecked")
public static Collection<File> splitPath(File path, boolean readable) {
Deque q = new LinkedList();
Deque<File> q = new LinkedList<>();
q.addFirst(path);

for (File p = path.getParentFile(); p != null; p = p.getParentFile()) {
Expand Down Expand Up @@ -656,7 +635,6 @@ public static String getMimeTypeFromExtension(String fileExt) {
return (fileExt == null) ? null : MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExt);
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isWifiEthActive(Context context, String allowedNetworks) {
Context ctx = context.getApplicationContext();
ConnectivityManager cmgr = (ConnectivityManager) ctx.getSystemService(CONNECTIVITY_SERVICE);
Expand Down
Loading

0 comments on commit f998d29

Please sign in to comment.