Skip to content

Commit

Permalink
intermediate directory policy options in extract dialog; remove dupli…
Browse files Browse the repository at this point in the history
…cated variables for RH client's request and flag bit lengths
  • Loading branch information
pgp committed Mar 28, 2020
1 parent bb345f7 commit 3bfbf41
Show file tree
Hide file tree
Showing 26 changed files with 71 additions and 50 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
versionCode 156200324
versionName "1.5.6"
versionCode 157200328
versionName "1.5.7"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -pthread -frtti -fexceptions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ private void startDownloadOfLatestRelease(View unused) {
srcArchive,
outDir,
null,
null
null,
false
));
activity.startService(startIntent);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ExtractActivity extends EffectActivity implements FileSelectFragmen

RadioGroup intermediateDirectoryPolicyRadioGroup; // only enabled when extracting a whole archive (not extracting single items from within the archive)

private boolean smartDirectoryCreation = false;

private void getSrcArchiveWithSubDirOrFinish() {
srcArchiveWithSubDir = MainActivity.mainActivity.getCurrentDirCommander().getCurrentDirectoryPathname();
if (srcArchiveWithSubDir.providerType != ProviderType.LOCAL_WITHIN_ARCHIVE &&
Expand Down Expand Up @@ -107,9 +109,8 @@ else if (srcArchiveWithSubDir.providerType==ProviderType.LOCAL_WITHIN_ARCHIVE) {
intermediateDirectoryPolicyRadioGroup.findViewById(
intermediateDirectoryPolicyRadioGroup.getCheckedRadioButtonId()));

if (idx == 2) { // always create subdirectory
Toast.makeText(this, "Warning: smart directory policy not implemented yet", Toast.LENGTH_SHORT).show();
return;
if (idx == 2) { // smart subdirectory creation
smartDirectoryCreation = true;
}
else if (idx == 0) { // always create subdirectory
String archiveFilename = srcArchiveWithSubDir.getName();
Expand All @@ -130,7 +131,8 @@ else if (idx == 0) { // always create subdirectory
srcArchiveWithSubDir,
destDir,
password,
selectedItems
selectedItems,
smartDirectoryCreation
));
startService(startIntent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public enum ControlCodes {
// ACTION_CANCEL((byte)0x1E),
ACTION_EXIT((byte)0x1F);

public static final int rq_bit_length = 5;
public static final int flags_bit_length = 3;

final byte value;
static final Map<Byte,ControlCodes> codeMap = new HashMap<Byte,ControlCodes>(){{
for (ControlCodes x: ControlCodes.values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
public class RemoteServerManager extends RemoteManager {

public static final AtomicReference<Thread> rhssManagerThreadRef = new AtomicReference<>(null);
private static final int rq_bit_length = 5;

private final byte rq_byte = ControlCodes.REMOTE_SERVER_MANAGEMENT.getValue();

Expand All @@ -42,8 +41,8 @@ private RemoteServerManager() throws IOException {
private boolean start_rhss(boolean announce, String... servedPaths) throws IOException {
// start RH remote server instance
byte rq = announce?
(byte)(rq_byte ^ (5 << rq_bit_length)) : // flags: 101, start with UDP broadcast announce
(byte)(rq_byte ^ (7 << rq_bit_length)); // flags: 111, no announce
(byte)(rq_byte ^ (5 << ControlCodes.rq_bit_length)) : // flags: 101, start with UDP broadcast announce
(byte)(rq_byte ^ (7 << ControlCodes.rq_bit_length)); // flags: 111, no announce
o.write(rq);

if(servedPaths.length == 0)
Expand Down Expand Up @@ -84,7 +83,7 @@ private boolean stop_rhss() throws IOException {

// true: running, false: not running
private boolean status_rhss() throws IOException {
byte rq = (byte)(rq_byte ^ (2 << rq_bit_length)); // flags: 010
byte rq = (byte)(rq_byte ^ (2 << ControlCodes.rq_bit_length)); // flags: 010
o.write(rq);

int resp = receiveBaseResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ error results (among which, the null or wrong password one) are within GenericDi
public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive,
BasePathContent destDirectory,
@Nullable String password,
@Nullable List<String> filenames) throws IOException {
@Nullable List<String> filenames,
boolean smartDirectoryCreation) throws IOException {

if (destDirectory.providerType != ProviderType.LOCAL) {
throw new RuntimeException("Forbidden type for destination directory");
Expand All @@ -699,7 +700,7 @@ public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive,
switch (srcArchive.providerType) {
case LOCAL:
// entryIdxs will be ignored, extract all, no need to preload VMap
return extract(srcArchive.dir,destDirectory.dir,password,null); // extract all
return extract(srcArchive.dir,destDirectory.dir,password,null,smartDirectoryCreation); // extract all
case LOCAL_WITHIN_ARCHIVE:
break;
default:
Expand All @@ -716,7 +717,7 @@ public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive,
if (filenames == null || filenames.size()==0) {
if (srcArchive.dir == null || srcArchive.dir.equals("") || srcArchive.dir.equals("/")) {
// no selection in root dir of archive, extract all
return extract(((ArchivePathContent)srcArchive).archivePath,destDirectory.dir,password,null); // extract all
return extract(((ArchivePathContent)srcArchive).archivePath,destDirectory.dir,password,null,smartDirectoryCreation); // extract all
}
else {
// no selection in subpath of archive
Expand All @@ -735,7 +736,8 @@ public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive,
return extract(((ArchivePathContent)srcArchive).archivePath,
destDirectory.dir,
password,
new RelativeExtractEntries(stripPathLen,entries));
new RelativeExtractEntries(stripPathLen,entries),
smartDirectoryCreation);
}

@Override
Expand Down Expand Up @@ -799,10 +801,11 @@ private List<Integer> getEntries(ArchiveVMap vMap, String relToArchivePathname)
private FileOpsErrorCodes extract(String archive,
String directory,
@Nullable String password,
@Nullable RelativeExtractEntries entries) throws IOException {
@Nullable RelativeExtractEntries entries,
boolean smartDirectoryCreation) throws IOException {
rs = getStreams();

extract_rq rq = new extract_rq(archive,directory,password,null,entries);
extract_rq rq = new extract_rq(archive,directory,password,null,entries, smartDirectoryCreation);
rq.write(rs.o);

FileOpsErrorCodes ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else if (fx instanceof String && fy instanceof String) {
public void write(OutputStream outputStream) throws IOException {
try(FlushingBufferedOutputStream nbf = new FlushingBufferedOutputStream(outputStream)) {
// write control byte
nbf.write(requestType.getValue());
nbf.write(getRequestByteWithFlags());
// write lengths and fields
nbf.write(Misc.castUnsignedNumberToBytes(lx,2));
nbf.write(Misc.castUnsignedNumberToBytes(ly,2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

public abstract class SinglePath_rq {
static final Charset UTF8 = Charset.forName("UTF-8");
protected static final int rq_bit_length = 5;
protected static final int flags_bit_length = 3;

public ControlCodes requestType;
public int pathname_len;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public create_rq(Object pathname, FileCreationAdvancedOptions fileOptions) {
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
// customize with flag bits
rq ^= ((fileMode == FileMode.FILE ?1:0) << (rq_bit_length));
rq ^= ((fileMode == FileMode.FILE ?1:0) << (ControlCodes.rq_bit_length));
if (fileOptions != null && fileMode == FileMode.FILE)
rq ^= (2 << rq_bit_length);
rq ^= (2 << ControlCodes.rq_bit_length);
return rq;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public byte getRequestByteWithFlags() {
// write request byte
byte rq = requestType.getValue();
// customize with flag bits
for (int i=0;i<flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+rq_bit_length));
for (int i=0;i<ControlCodes.flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+ControlCodes.rq_bit_length));
}
return rq;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@ public class extract_rq extends PairOfPaths_rq {
public byte[] password;
public byte[] subDir;
public RelativeExtractEntries entries;
public boolean smartDirectoryCreation;

public extract_rq(Object fx, Object fy, // source archive and destination directory (both LocalPathContent)
@Nullable Object password, // password will be used if present to try to open archive
@Nullable Object subDir, // subDir prefix will be removed by entries path when extracting
@Nullable RelativeExtractEntries entries // for selective extraction
@Nullable RelativeExtractEntries entries, // for selective extraction
boolean smartDirectoryCreation // valid only if entries is null
) {
super(fx, fy);
requestType = ControlCodes.ACTION_EXTRACT;
this.smartDirectoryCreation = smartDirectoryCreation;
if (password != null)
this.password = (password instanceof String)?((String) password).getBytes():(byte[])password;
if (subDir != null)
this.subDir = (subDir instanceof String)?((String) subDir).getBytes():(byte[])subDir;
this.entries = entries;
}

@Override
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
rq ^= ((smartDirectoryCreation?6:7) << ControlCodes.rq_bit_length); // 110 vs 111 flags
return rq;
}

@Override
public void write(OutputStream outputStream) throws IOException {
super.write(outputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public fileio_rq(Object pathname, FileIOMode mode) {
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
// customize with flag bits (only one bit)
rq ^= ((mode == FileIOMode.READFROMFILE?1:0) << (rq_bit_length));
rq ^= ((mode == FileIOMode.READFROMFILE?1:0) << (ControlCodes.rq_bit_length));
return rq;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import it.pgp.xfiles.roothelperclient.ControlCodes;
import it.pgp.xfiles.utils.Misc;

import static it.pgp.xfiles.roothelperclient.reqs.SinglePath_rq.rq_bit_length;

public class find_rq {

public final ControlCodes requestType = ControlCodes.ACTION_FIND;
Expand Down Expand Up @@ -116,7 +114,7 @@ public find_rq() {
public void writefind_rq(OutputStream outputStream) throws IOException {
try(FlushingBufferedOutputStream nbf = new FlushingBufferedOutputStream(outputStream)) {
byte rq = requestType.getValue();
rq ^= (flagBits.getFlagBits() << (rq_bit_length));
rq ^= (flagBits.getFlagBits() << (ControlCodes.rq_bit_length));
nbf.write(rq);
if (flagBits.cancelCurrentSearch) return;
nbf.write(searchBits.getSearchBits());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void write(OutputStream outputStream) throws IOException {
// write dirHashOpts
byte dirHashOpts_ = 0;
// customize with flag bits
for (int i=0;i<flags_bit_length;i++)
for (int i=0;i<ControlCodes.flags_bit_length;i++)
dirHashOpts_ ^= ((dirHashOpts.get(i)?1:0) << i);
nbf.write(dirHashOpts_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import it.pgp.xfiles.utils.Misc;

public class link_rq extends PairOfPaths_rq {
protected static final int rq_bit_length = 5;

boolean isHardLink;

Expand All @@ -22,7 +21,7 @@ public link_rq(Object fx, Object fy, boolean isHardLink) {
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
// customize with flag bits
rq ^= ((isHardLink?2:0) << (rq_bit_length));
rq ^= ((isHardLink?2:0) << (ControlCodes.rq_bit_length));
return rq;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ else if (password instanceof byte[]) {
@Override
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
rq ^= (flags << rq_bit_length);
rq ^= (flags << ControlCodes.rq_bit_length);
return rq;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

public class multiStats_rq {
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final int rq_bit_length = 5;
private static final int flags_bit_length = 3;

public ControlCodes requestType;
public List<String> pathnames;
Expand All @@ -37,8 +35,8 @@ public void write(OutputStream outputStream) throws IOException {
// write request byte (customized with flags)
byte rq = requestType.getValue();
// customize with flag bits
for (int i=0;i<flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+rq_bit_length));
for (int i=0;i<ControlCodes.flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+ControlCodes.rq_bit_length));
}
nbf.write(rq);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.pgp.xfiles.roothelperclient.reqs;

import it.pgp.xfiles.roothelperclient.ControlCodes;

public class retrieveHomePath_rq extends ls_rq {

public byte flags = 0x02; // 0x02 = {0,1,0} (bitmask)
Expand All @@ -11,7 +13,7 @@ public retrieveHomePath_rq(Object dirPath) {
@Override
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
rq ^= (flags << rq_bit_length);
rq ^= (flags << ControlCodes.rq_bit_length);
return rq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public singleStats_rq(Object pathname, FileMode fileMode) {
public byte getRequestByteWithFlags() {
byte rq = requestType.getValue();
// customize with flag bits
for (int i=0;i<flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+rq_bit_length));
for (int i=0;i<ControlCodes.flags_bit_length;i++) {
rq ^= ((flags.get(i)?1:0) << (i+ControlCodes.rq_bit_length));
}
return rq;
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/it/pgp/xfiles/service/ExtractTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ExtractTask extends RootHelperClientTask {
private BasePathContent destDirectory;
private String password;
private List<String> filenames;
private boolean smartDirectoryCreation;

private static final FileOpsErrorCodes defaultErrorResult = FileOpsErrorCodes.TRANSFER_ERROR;
private BasePathContent currentDir;
Expand All @@ -39,6 +40,7 @@ public class ExtractTask extends RootHelperClientTask {
destDirectory = params.destDirectory;
password = params.password;
filenames = params.filenames;
smartDirectoryCreation = params.smartDirectoryCreation;
}

@Override
Expand All @@ -65,7 +67,8 @@ protected Object doInBackground(Object[] params) {
srcArchive,
destDirectory,
password,
filenames);
filenames,
smartDirectoryCreation);
}
catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ public class ExtractParams implements Serializable {
public BasePathContent destDirectory;
public String password;
public List<String> filenames;
public boolean smartDirectoryCreation;

public ExtractParams(BasePathContent srcArchive,
BasePathContent destDirectory,
@Nullable String password,
@Nullable List<String> filenames) {
@Nullable List<String> filenames,
boolean smartDirectoryCreation) {
this.srcArchive = srcArchive;
this.destDirectory = destDirectory;
this.password = password;
this.filenames = filenames;
this.smartDirectoryCreation = smartDirectoryCreation;
}

public void setPassword(String password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ public int compressToArchive(BasePathContent srcDirectory,
public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive,
BasePathContent destDirectory,
@Nullable String password,
@Nullable List<String> filenames) throws IOException {
@Nullable List<String> filenames,
boolean smartDirectoryCreation) throws IOException {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public int compressToArchive(BasePathContent srcDirectory, BasePathContent destA
}

@Override
public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive, BasePathContent destDirectory, @Nullable String password, @Nullable List<String> filenames) throws IOException {
public FileOpsErrorCodes extractFromArchive(BasePathContent srcArchive, BasePathContent destDirectory, @Nullable String password, @Nullable List<String> filenames, boolean smartDirectoryCreation) throws IOException {
return null;
}

Expand Down
Loading

0 comments on commit 3bfbf41

Please sign in to comment.