Partly revert last commit

This commit is contained in:
DrKLO 2014-06-16 18:31:12 +04:00
parent 358a067acc
commit 69c3c6066e
5 changed files with 16 additions and 133 deletions

View File

@ -337,7 +337,7 @@ public class FileLoader {
return memCache.get(key) != null;
}
public void uploadFile(final String location, final String originalLocation, final boolean encrypted) {
public void uploadFile(final String location, final boolean encrypted) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
@ -350,7 +350,7 @@ public class FileLoader {
return;
}
}
FileUploadOperation operation = new FileUploadOperation(location, originalLocation, encrypted);
FileUploadOperation operation = new FileUploadOperation(location, encrypted);
if (encrypted) {
uploadOperationPathsEnc.put(location, operation);
} else {

View File

@ -13,14 +13,11 @@ import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.Semaphore;
public class FileUploadOperation {
private int uploadChunkSize = 1024 * 32;
private String uploadingFilePath;
private String originalPath;
public int state = 0;
private byte[] readBuffer;
public FileUploadOperationDelegate delegate;
@ -45,9 +42,8 @@ public class FileUploadOperation {
public abstract void didChangedUploadProgress(FileUploadOperation operation, float progress);
}
public FileUploadOperation(String location, String originalLocaltion, boolean encrypted) {
public FileUploadOperation(String location, boolean encrypted) {
uploadingFilePath = location;
originalPath = originalLocaltion;
if (encrypted) {
iv = new byte[32];
key = new byte[32];
@ -106,26 +102,6 @@ public class FileUploadOperation {
try {
if (stream == null) {
if (originalPath != null) {
Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>();
String path = originalPath;
if (key != null) {
path += "e";
}
MessagesStorage.getInstance().getSentFile(path, semaphore, result);
semaphore.acquire();
if (!result.isEmpty()) {
TLObject object = result.get(0);
if (object instanceof TLRPC.InputFile) {
delegate.didFinishUploadingFile(FileUploadOperation.this, (TLRPC.InputFile) object, null);
return;
} else if (object instanceof TLRPC.InputEncryptedFile) {
delegate.didFinishUploadingFile(FileUploadOperation.this, null, (TLRPC.InputEncryptedFile) object);
return;
}
}
}
File cacheFile = new File(uploadingFilePath);
stream = new FileInputStream(cacheFile);
totalFileSize = cacheFile.length();
@ -210,9 +186,6 @@ public class FileUploadOperation {
result.id = currentFileId;
result.name = uploadingFilePath.substring(uploadingFilePath.lastIndexOf("/") + 1);
delegate.didFinishUploadingFile(FileUploadOperation.this, result, null);
if (originalPath != null) {
MessagesStorage.getInstance().putSentFile(originalPath, result, null, null);
}
} else {
TLRPC.InputEncryptedFile result;
if (isBigFile) {
@ -227,9 +200,6 @@ public class FileUploadOperation {
result.iv = iv;
result.key = key;
delegate.didFinishUploadingFile(FileUploadOperation.this, null, result);
if (originalPath != null) {
MessagesStorage.getInstance().putSentFile(originalPath + "e", result, key, iv);
}
}
} else {
startUploadRequest();

View File

@ -127,7 +127,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public TLRPC.TL_messages_sendMedia sendRequest;
public TLRPC.TL_decryptedMessage sendEncryptedRequest;
public int type;
public String originalPath;
public TLRPC.FileLocation location;
public TLRPC.TL_video videoLocation;
public TLRPC.TL_audio audioLocation;
@ -588,7 +587,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) {
uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
FileLoader.getInstance().uploadFile(uploadingAvatar, null, false);
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
}
}
@ -1732,7 +1731,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
type = 2;
newMsg.message = "-1";
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
newMsg.attachPath = originalPath;
newMsg.attachPath = Utilities.getCacheDir() + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
} else if (video != null) {
newMsg = new TLRPC.TL_message();
newMsg.media = new TLRPC.TL_messageMediaVideo();
@ -1883,7 +1882,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (type == 2) {
reqSend.media = new TLRPC.TL_inputMediaUploadedPhoto();
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 0;
delayedMessage.obj = newMsgObj;
@ -1895,7 +1893,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.w = video.w;
reqSend.media.h = video.h;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 1;
delayedMessage.obj = newMsgObj;
@ -1924,7 +1921,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.mime_type = document.mime_type;
reqSend.media.file_name = document.file_name;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 2;
delayedMessage.obj = newMsgObj;
@ -1935,7 +1931,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media = new TLRPC.TL_inputMediaUploadedAudio();
reqSend.media.duration = audio.duration;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 3;
delayedMessage.obj = newMsgObj;
@ -1965,7 +1960,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.size = big.size;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 0;
delayedMessage.obj = newMsgObj;
@ -1983,7 +1977,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.thumb_w = video.thumb.w;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 1;
delayedMessage.obj = newMsgObj;
@ -2015,7 +2008,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.mime_type = document.mime_type;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 2;
delayedMessage.obj = newMsgObj;
@ -2028,7 +2020,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.size = audio.size;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 3;
delayedMessage.obj = newMsgObj;
@ -2463,23 +2454,23 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
FileLoader.getInstance().uploadFile(location, false);
} else {
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
FileLoader.getInstance().uploadFile(location, true);
}
} else if (message.type == 1) {
if (message.sendRequest != null) {
if (message.sendRequest.media.thumb == null) {
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, message.originalPath + "thumb", false);
FileLoader.getInstance().uploadFile(location, false);
} else {
String location = message.videoLocation.path;
if (location == null) {
location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
FileLoader.getInstance().uploadFile(location, false);
}
} else {
String location = message.videoLocation.path;
@ -2487,29 +2478,29 @@ public class MessagesController implements NotificationCenter.NotificationCenter
location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
FileLoader.getInstance().uploadFile(location, true);
}
} else if (message.type == 2) {
if (message.sendRequest != null && message.sendRequest.media.thumb == null && message.location != null) {
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, message.originalPath + "thumb", false);
FileLoader.getInstance().uploadFile(location, false);
} else {
String location = message.documentLocation.path;
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
FileLoader.getInstance().uploadFile(location, false);
} else {
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
FileLoader.getInstance().uploadFile(location, true);
}
}
} else if (message.type == 3) {
String location = message.audioLocation.path;
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, null, false);
FileLoader.getInstance().uploadFile(location, false);
} else {
FileLoader.getInstance().uploadFile(location, null, true);
FileLoader.getInstance().uploadFile(location, true);
}
}
}

View File

@ -97,8 +97,6 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
database.executeFast("CREATE TABLE user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
database.executeFast("CREATE TABLE sent_files(uid TEXT PRIMARY KEY, data BLOB, key BLOB, iv BLOB)").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
@ -168,8 +166,6 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
database.executeFast("CREATE TABLE IF NOT EXISTS sent_files(uid TEXT PRIMARY KEY, data BLOB, key BLOB, iv BLOB)").stepThis().dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -1500,80 +1496,6 @@ public class MessagesStorage {
});
}
public void getSentFile(final String path, final Semaphore semaphore, final ArrayList<TLObject> result) {
if (path == null || semaphore == null || result == null) {
return;
}
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLiteCursor cursor = database.queryFinalized("SELECT data, key, iv FROM sent_files WHERE uid = '" + id + "'");
if (cursor.next()) {
byte[] fileData = cursor.byteArrayValue(0);
if (fileData != null) {
SerializedData data = new SerializedData(fileData);
TLObject file = TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (file instanceof TLRPC.InputEncryptedFile) {
TLRPC.InputEncryptedFile encFile = (TLRPC.InputEncryptedFile)file;
encFile.key = cursor.byteArrayValue(1);
encFile.iv = cursor.byteArrayValue(2);
if (encFile.key != null && encFile.iv != null) {
result.add(file);
}
} else if (file instanceof TLRPC.InputFile) {
result.add(file);
}
}
}
cursor.dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
semaphore.release();
}
}
});
}
public void putSentFile(final String path, final TLObject file, final byte[] key, final byte[] iv) {
if (path == null || file == null) {
return;
}
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLitePreparedStatement state = null;
if (key != null && iv != null) {
state = database.executeFast("REPLACE INTO sent_files VALUES(?, ?, ?, ?)");
} else {
state = database.executeFast("REPLACE INTO sent_files VALUES(?, ?, NULL, NULL)");
}
state.requery();
SerializedData data = new SerializedData();
file.serializeToStream(data);
state.bindString(1, id);
state.bindByteArray(2, data.toByteArray());
if (key != null && iv != null) {
state.bindByteArray(3, key);
state.bindByteArray(4, iv);
}
state.step();
state.dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void getEncryptedChat(final int chat_id, final Semaphore semaphore, final ArrayList<TLObject> result) {
if (semaphore == null || result == null) {
return;

View File

@ -129,7 +129,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, null, false);
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
}
}
}