Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NGC group images #16

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
runs-on: macos-11
needs: update-nightly-tag
if: |
always() &&
false &&
(needs.update-nightly-tag.result == 'success' ||
needs.update-nightly-tag.result == 'skipped')
permissions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ deps/
toxid.txt
main.db
_BACKUP/
datadir/
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ compose.desktop {
mainClass = "MainKt"
// jvmArgs += listOf("-Xmx2G")
// args += listOf("-customArgument")
// jvmArgs += listOf("-Dcom.apple.mrj.application.apple.menu.about.name=\"TRIfA - Material\" -Dapple.awt.application.name=\"TRIfA - Material\"")
jvmArgs += listOf("-Dcom.apple.mrj.application.apple.menu.about.name=TRIfA")
jvmArgs += listOf("-Dapple.awt.application.name=TRIfA")

buildTypes.release.proguard {
optimize.set(false)
Expand Down
11 changes: 11 additions & 0 deletions resources/common/main.db.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,14 @@ CREATE INDEX IF NOT EXISTS "index_is_relay_on_FriendList" ON "FriendList" (
"is_relay"
);

ALTER TABLE GroupMessage add path_name TEXT DEFAULT NULL;
CREATE INDEX IF NOT EXISTS "index_path_name_on_GroupMessage" ON "GroupMessage" ("path_name");

ALTER TABLE GroupMessage add file_name TEXT DEFAULT NULL;
CREATE INDEX IF NOT EXISTS "index_file_name_on_GroupMessage" ON "GroupMessage" ("file_name");

ALTER TABLE GroupMessage add filename_fullpath TEXT DEFAULT NULL;
CREATE INDEX IF NOT EXISTS "index_filename_fullpath_on_GroupMessage" ON "GroupMessage" ("filename_fullpath");

ALTER TABLE GroupMessage add filesize INTEGER NOT NULL DEFAULT 0;
CREATE INDEX IF NOT EXISTS "index_filesize_on_GroupMessage" ON "GroupMessage" ("filesize");
42 changes: 37 additions & 5 deletions src/main/java/com/zoffcc/applications/sorm/GroupMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,23 @@ public class GroupMessage

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
String msg_id_hash = null; // 32byte hash
public String msg_id_hash = null; // 32byte hash

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
public String path_name = null;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
public String file_name = null;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
public String filename_fullpath = null;

@Column(indexed = true, helpers = Column.Helpers.ALL)
@Nullable
public long filesize = 0L;

static GroupMessage deep_copy(GroupMessage in)
{
Expand All @@ -109,6 +125,10 @@ static GroupMessage deep_copy(GroupMessage in)
out.tox_group_peername = in.tox_group_peername;
out.was_synced = in.was_synced;
out.msg_id_hash = in.msg_id_hash;
out.path_name = in.path_name;
out.file_name = in.file_name;
out.filename_fullpath = in.filename_fullpath;
out.filesize = in.filesize;

return out;
}
Expand All @@ -120,7 +140,8 @@ public String toString()
", tox_peerpubkey=" + "*tox_peerpubkey*" + ", private_message=" + private_message + ", direction=" +
direction + ", TRIFA_MESSAGE_TYPE=" + TRIFA_MESSAGE_TYPE + ", TOX_MESSAGE_TYPE=" + TOX_MESSAGE_TYPE +
", sent_timestamp=" + sent_timestamp + ", rcvd_timestamp=" + rcvd_timestamp + ", read=" + read +
", text=" + "xxxxxx" + ", is_new=" + is_new + ", was_synced=" + was_synced;
", text=" + "xxxxxx" + ", is_new=" + is_new + ", was_synced=" + was_synced + ", path_name=" + path_name +
", file_name=" + file_name + ", filename_fullpath=" + filename_fullpath + ", filesize=" + filesize;
}

String sql_start = "";
Expand Down Expand Up @@ -158,7 +179,10 @@ public List<GroupMessage> toList()
out.text = rs.getString("text");
out.was_synced = rs.getBoolean("was_synced");
out.msg_id_hash = rs.getString("msg_id_hash");

out.path_name = rs.getString("path_name");
out.file_name = rs.getString("file_name");
out.filename_fullpath = rs.getString("filename_fullpath");
out.filesize = rs.getLong("filesize");
list.add(out);
}

Expand Down Expand Up @@ -202,7 +226,11 @@ public long insert()
"is_new," +
"text," +
"was_synced,"+
"msg_id_hash"+
"msg_id_hash,"+
"path_name," +
"file_name," +
"filename_fullpath," +
"filesize" +
")" +
"values" +
"(" +
Expand All @@ -220,7 +248,11 @@ public long insert()
"'"+b(this.is_new)+"'," +
"'"+s(this.text)+"'," +
"'"+b(this.was_synced)+"'," +
"'"+s(this.msg_id_hash)+"'" +
"'"+s(this.msg_id_hash)+"'," +
"'"+s(this.path_name)+"'," +
"'"+s(this.file_name)+"'," +
"'"+s(this.filename_fullpath)+"'," +
"'"+s(this.filesize)+"'" +
")";

if (ORMA_TRACE)
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/com/zoffcc/applications/sorm/OrmaDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OrmaDatabase
private static final String TAG = "trifa.OrmaDatabase";
final static boolean ORMA_TRACE = false; // set "false" for release builds

private static final String CREATE_DB_FILE_SHA256SUM = "GE/avgqgDL4L1v35QvL2DIXdFMVOVKm8Ic8hG7v1BeA=";
private static final String CREATE_DB_FILE_SHA256SUM = "HJC9IOw3S0l53MKJOLXV1iUCWaglwXLyW9gncs52wds=";
static Connection sqldb = null;
static int current_db_version = 0;

Expand Down Expand Up @@ -501,7 +501,51 @@ public static int update_db(int current_db_version)
}
}

final int new_db_version = 10;
if (current_db_version < 11)
{
try
{
final String update_001 = "alter table GroupMessage add path_name TEXT DEFAULT NULL;" + "\n" +
"CREATE INDEX index_path_name_on_GroupMessage ON GroupMessage (path_name);";
run_multi_sql(update_001);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
final String update_002 = "alter table GroupMessage add file_name TEXT DEFAULT NULL;" + "\n" +
"CREATE INDEX index_file_name_on_GroupMessage ON GroupMessage (file_name);";
run_multi_sql(update_002);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
final String update_003 = "alter table GroupMessage add filename_fullpath TEXT DEFAULT NULL;" + "\n" +
"CREATE INDEX index_filename_fullpath_on_GroupMessage ON GroupMessage (filename_fullpath);";
run_multi_sql(update_003);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
final String update_004 = "alter table GroupMessage add filesize INTEGER NOT NULL DEFAULT 0;" + "\n" +
"CREATE INDEX index_filesize_on_GroupMessage ON GroupMessage (filesize);";
run_multi_sql(update_004);
}
catch (Exception e)
{
e.printStackTrace();
}
}

final int new_db_version = 11;
set_new_db_version(new_db_version);
// return the updated DB VERSION
return new_db_version;
Expand Down
151 changes: 151 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/HelperFiletransfer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.zoffcc.applications.trifa;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Random;

import static com.zoffcc.applications.trifa.TRIFAGlobals.VFS_FILE_DIR;
import static com.zoffcc.applications.trifa.TRIFAGlobals.VFS_PREFIX;

public class HelperFiletransfer {
private static final String TAG = "trifa.Hlp.Filetransfer";

public static String filter_out_specials_from_filepath(String path)
{
try
{
// TODO: be less strict here, but really actually test it then!
return path.replaceAll("[^a-zA-Z0-9_.]", "_");
}
catch (Exception e)
{
e.printStackTrace();
return path;
}
}

public static String filter_out_specials(String in)
{
try
{
return in.replaceAll("[^a-zA-Z0-9]", "");
}
catch (Exception e)
{
e.printStackTrace();
return in;
}
}

public static String bytesToString(byte[] bytes)
{
return Base64.getEncoder().encodeToString(bytes);
}

public static byte[] StringToBytes2(String in)
{
try
{
return in.getBytes(StandardCharsets.UTF_8);
}
catch (Exception e)
{
// TODO: fix me!!!!!
// TODO: fix me!!!!!
// TODO: fix me!!!!!
e.printStackTrace();
return null;
// TODO: fix me!!!!!
// TODO: fix me!!!!!
// TODO: fix me!!!!!
}
}

public static byte[] sha256(byte[] input)
{
try
{
return MessageDigest.getInstance("SHA-256").digest(input);
}
catch (NoSuchAlgorithmException e)
{
throw new RuntimeException(e);
}
}

public static String get_incoming_filetransfer_local_filename(String incoming_filename, String friend_pubkey_str)
{
String result = filter_out_specials_from_filepath(incoming_filename);
String wanted_full_filename_path = VFS_FILE_DIR + "/" + friend_pubkey_str;

// Log.i(TAG, "check_auto_accept_incoming_filetransfer:start=" + incoming_filename + " " + result + " " +
// wanted_full_filename_path);

File f1 = new File(wanted_full_filename_path + "/" + result);

if (f1.exists())
{
Random random = new Random();
long new_random_log = (long) random.nextInt() + (1L << 31);

// Log.i(TAG, "check_auto_accept_incoming_filetransfer:new_random_log=" + new_random_log);

String random_filename_addon = filter_out_specials(
bytesToString(sha256(
StringToBytes2("" + new_random_log))));
// Log.i(TAG, "check_auto_accept_incoming_filetransfer:random_filename_addon=" + random_filename_addon);

String extension = "";

try
{
extension = result.substring(result.lastIndexOf("."));

if (extension.equalsIgnoreCase("."))
{
extension = "";
}
}
catch (Exception e)
{
extension = "";
}

result = result + "_" + random_filename_addon + extension;

// Log.i(TAG, "check_auto_accept_incoming_filetransfer:result=" + result);
}

return result;
}

static void save_group_incoming_file(String file_path_name, String file_name, byte[] data, long buffer_offset, long write_bytes)
{
try
{
if (buffer_offset >= 2100000L)
{
return;
}
if (write_bytes >= 2100000L)
{
return;
}

File outfile = new File(file_path_name + "/" + file_name);
FileOutputStream outputStream = new FileOutputStream(outfile);
outputStream.write(data, (int)buffer_offset, (int)write_bytes);
outputStream.flush();
outputStream.close();
}
catch (Exception e)
{
e.printStackTrace();
Log.i(TAG, "save_group_incoming_file:EE");
}
}
}
Loading
Loading