take profile photos by android phone (still very buggy)
This commit is contained in:
1 parent
da843b4f06
commit
6d008cdc06
17 files changed
+339
-48
No files matched your search
@@ -15,6 +15,7 @@
|
|||||||
<AndroidApplication>True</AndroidApplication>
|
<AndroidApplication>True</AndroidApplication>
|
||||||
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
|
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
|
||||||
<AssemblyName>AndroidRemote</AssemblyName>
|
<AssemblyName>AndroidRemote</AssemblyName>
|
||||||
|
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -78,7 +79,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Resources\AboutResources.txt" />
|
<None Include="Resources\AboutResources.txt" />
|
||||||
<None Include="Assets\AboutAssets.txt" />
|
<None Include="Properties\AndroidManifest.xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AndroidResource Include="Resources\layout\Main.axml" />
|
<AndroidResource Include="Resources\layout\Main.axml" />
|
||||||
@@ -88,5 +89,6 @@
|
|||||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="ClientServerLib\" />
|
<Folder Include="ClientServerLib\" />
|
||||||
|
<Folder Include="Assets\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
|
using Android.Content.PM;
|
||||||
|
using Android.Graphics;
|
||||||
using Android.Runtime;
|
using Android.Runtime;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
|
using Android.Provider;
|
||||||
|
|
||||||
using ClientServerLib;
|
using ClientServerLib;
|
||||||
using Vocaluxe.Base.Server;
|
using Vocaluxe.Base.Server;
|
||||||
@@ -20,7 +24,14 @@ namespace AndroidRemote
|
|||||||
Button bLogin;
|
Button bLogin;
|
||||||
Button bUp;
|
Button bUp;
|
||||||
Button bDown;
|
Button bDown;
|
||||||
|
Button bSendAvatar;
|
||||||
bool loggedIn;
|
bool loggedIn;
|
||||||
|
byte[] fileBytes;
|
||||||
|
|
||||||
|
ImageView imageView;
|
||||||
|
Java.IO.File file;
|
||||||
|
Java.IO.File dir;
|
||||||
|
System.IO.FileStream fs;
|
||||||
|
|
||||||
protected override void OnCreate (Bundle bundle)
|
protected override void OnCreate (Bundle bundle)
|
||||||
{
|
{
|
||||||
@@ -46,12 +57,66 @@ namespace AndroidRemote
|
|||||||
bDown.Click += delegate {
|
bDown.Click += delegate {
|
||||||
client.SendMessage (CCommands.CreateCommandWithoutParams (CCommands.CommandSendKeyDown), OnResponse);
|
client.SendMessage (CCommands.CreateCommandWithoutParams (CCommands.CommandSendKeyDown), OnResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imageView = FindViewById<ImageView>(Resource.Id.imageView1);
|
||||||
|
|
||||||
|
bSendAvatar = FindViewById<Button> (Resource.Id.btSendAvatar);
|
||||||
|
bSendAvatar.Click += SendAvatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStop ()
|
protected override void OnStop ()
|
||||||
{
|
{
|
||||||
base.OnStop();
|
base.OnStop();
|
||||||
client.Close();
|
//client.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
||||||
|
{
|
||||||
|
base.OnActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
// make it available in the gallery
|
||||||
|
Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
|
||||||
|
Android.Net.Uri contentUri = Android.Net.Uri.FromFile(file);
|
||||||
|
mediaScanIntent.SetData(contentUri);
|
||||||
|
SendBroadcast(mediaScanIntent);
|
||||||
|
System.IO.FileInfo fi = new System.IO.FileInfo(file.Path);
|
||||||
|
fs = new System.IO.FileStream(file.Path, System.IO.FileMode.Open);
|
||||||
|
fileBytes = new byte[fi.Length];
|
||||||
|
fs.BeginRead (fileBytes, 0, (int)fi.Length, new AsyncCallback(OnFileRead), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileRead(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
if (fileBytes == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fs.Flush();
|
||||||
|
fs.Close();
|
||||||
|
client.SendMessage (CCommands.CreateCommandSendAvatarPictureJpg(fileBytes), OnResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsThereAnAppToTakePictures()
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(MediaStore.ActionImageCapture);
|
||||||
|
IList<ResolveInfo> availableActivities = PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
|
||||||
|
return availableActivities != null && availableActivities.Count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendAvatar(object sender, EventArgs eventArgs)
|
||||||
|
{
|
||||||
|
if (!IsThereAnAppToTakePictures())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Intent intent = new Intent(MediaStore.ActionImageCapture);
|
||||||
|
dir = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures), "AndroidRemote");
|
||||||
|
if (dir.Exists())
|
||||||
|
{
|
||||||
|
dir.Mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
file = new Java.IO.File(dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
|
||||||
|
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
|
||||||
|
StartActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Connect()
|
private void Connect()
|
||||||
@@ -138,6 +203,35 @@ namespace AndroidRemote
|
|||||||
Toast.MakeText(this, "Not Logged In", ToastLength.Short).Show();
|
Toast.MakeText(this, "Not Logged In", ToastLength.Short).Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BitmapHelpers
|
||||||
|
{
|
||||||
|
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
|
||||||
|
{
|
||||||
|
// First we get the the dimensions of the file on disk
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
|
||||||
|
BitmapFactory.DecodeFile(fileName, options);
|
||||||
|
|
||||||
|
// Next we calculate the ratio that we need to resize the image by
|
||||||
|
// in order to fit the requested dimensions.
|
||||||
|
int outHeight = options.OutHeight;
|
||||||
|
int outWidth = options.OutWidth;
|
||||||
|
int inSampleSize = 1;
|
||||||
|
|
||||||
|
if (outHeight > height || outWidth > width)
|
||||||
|
{
|
||||||
|
inSampleSize = outWidth > outHeight
|
||||||
|
? outHeight / height
|
||||||
|
: outWidth / width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we will load the image and have BitmapFactory resize it for us.
|
||||||
|
options.InSampleSize = inSampleSize;
|
||||||
|
options.InJustDecodeBounds = false;
|
||||||
|
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
|
||||||
|
return resizedBitmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="AndroidRemote.AndroidRemote">
|
||||||
|
<uses-sdk />
|
||||||
|
<application android:label="AndroidRemote" android:icon="@drawable/icon"></application>
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
</manifest>
|
||||||
+22
-13
@@ -72,9 +72,15 @@ namespace AndroidRemote
|
|||||||
// aapt resource value: 0x7f060005
|
// aapt resource value: 0x7f060005
|
||||||
public const int btLogin = 2131099653;
|
public const int btLogin = 2131099653;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f060008
|
||||||
|
public const int btSendAvatar = 2131099656;
|
||||||
|
|
||||||
// aapt resource value: 0x7f060006
|
// aapt resource value: 0x7f060006
|
||||||
public const int btUp = 2131099654;
|
public const int btUp = 2131099654;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f060009
|
||||||
|
public const int imageView1 = 2131099657;
|
||||||
|
|
||||||
// aapt resource value: 0x7f060001
|
// aapt resource value: 0x7f060001
|
||||||
public const int tbIP = 2131099649;
|
public const int tbIP = 2131099649;
|
||||||
|
|
||||||
@@ -137,32 +143,35 @@ namespace AndroidRemote
|
|||||||
// aapt resource value: 0x7f040004
|
// aapt resource value: 0x7f040004
|
||||||
public const int button_logout = 2130968580;
|
public const int button_logout = 2130968580;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f040007
|
||||||
|
public const int button_send_avatar = 2130968583;
|
||||||
|
|
||||||
// aapt resource value: 0x7f040005
|
// aapt resource value: 0x7f040005
|
||||||
public const int button_up = 2130968581;
|
public const int button_up = 2130968581;
|
||||||
|
|
||||||
// aapt resource value: 0x7f04000d
|
// aapt resource value: 0x7f04000e
|
||||||
public const int ip_address = 2130968589;
|
public const int ip_address = 2130968590;
|
||||||
|
|
||||||
// aapt resource value: 0x7f040007
|
|
||||||
public const int message_connected = 2130968583;
|
|
||||||
|
|
||||||
// aapt resource value: 0x7f040008
|
// aapt resource value: 0x7f040008
|
||||||
public const int message_disconnected = 2130968584;
|
public const int message_connected = 2130968584;
|
||||||
|
|
||||||
// aapt resource value: 0x7f040009
|
// aapt resource value: 0x7f040009
|
||||||
public const int message_logged_in = 2130968585;
|
public const int message_disconnected = 2130968585;
|
||||||
|
|
||||||
// aapt resource value: 0x7f04000a
|
// aapt resource value: 0x7f04000a
|
||||||
public const int message_logged_out = 2130968586;
|
public const int message_logged_in = 2130968586;
|
||||||
|
|
||||||
// aapt resource value: 0x7f04000e
|
|
||||||
public const int password = 2130968590;
|
|
||||||
|
|
||||||
// aapt resource value: 0x7f04000b
|
// aapt resource value: 0x7f04000b
|
||||||
public const int text_ip_address = 2130968587;
|
public const int message_logged_out = 2130968587;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f04000f
|
||||||
|
public const int password = 2130968591;
|
||||||
|
|
||||||
// aapt resource value: 0x7f04000c
|
// aapt resource value: 0x7f04000c
|
||||||
public const int text_password = 2130968588;
|
public const int text_ip_address = 2130968588;
|
||||||
|
|
||||||
|
// aapt resource value: 0x7f04000d
|
||||||
|
public const int text_password = 2130968589;
|
||||||
|
|
||||||
static String()
|
static String()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,4 +49,15 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/btDown"
|
android:id="@+id/btDown"
|
||||||
android:enabled="false" />
|
android:enabled="false" />
|
||||||
|
<Button
|
||||||
|
android:text="@string/button_send_avatar"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/btSendAvatar"
|
||||||
|
android:enabled="true" />
|
||||||
|
<ImageView
|
||||||
|
android:src="@android:drawable/ic_menu_gallery"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/imageView1" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
<string name="button_logout">Logout</string>
|
<string name="button_logout">Logout</string>
|
||||||
<string name="button_up">Up</string>
|
<string name="button_up">Up</string>
|
||||||
<string name="button_down">Down</string>
|
<string name="button_down">Down</string>
|
||||||
|
<string name="button_send_avatar">Send Avatar Picture</string>
|
||||||
<string name="message_connected">Connected</string>
|
<string name="message_connected">Connected</string>
|
||||||
<string name="message_disconnected">Disconnected</string>
|
<string name="message_disconnected">Disconnected</string>
|
||||||
<string name="message_logged_in">Logged in</string>
|
<string name="message_logged_in">Logged in</string>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace ClientServerLib
|
|||||||
private CConnection connection;
|
private CConnection connection;
|
||||||
private List<SRequest> requests;
|
private List<SRequest> requests;
|
||||||
private List<SRequest> responses;
|
private List<SRequest> responses;
|
||||||
|
private Object mutexRequests = new Object();
|
||||||
private OnConnectionChanged onConnectionChanged;
|
private OnConnectionChanged onConnectionChanged;
|
||||||
private OnSend onSend;
|
private OnSend onSend;
|
||||||
private OnReceived onReceived;
|
private OnReceived onReceived;
|
||||||
@@ -70,7 +71,7 @@ namespace ClientServerLib
|
|||||||
{
|
{
|
||||||
doConnect = false;
|
doConnect = false;
|
||||||
|
|
||||||
lock (requests)
|
lock (mutexRequests)
|
||||||
{
|
{
|
||||||
requests.Clear();
|
requests.Clear();
|
||||||
}
|
}
|
||||||
@@ -96,7 +97,7 @@ namespace ClientServerLib
|
|||||||
req.Callback = Callback;
|
req.Callback = Callback;
|
||||||
req.Response = null;
|
req.Response = null;
|
||||||
|
|
||||||
lock (requests)
|
lock (mutexRequests)
|
||||||
{
|
{
|
||||||
requests.Add(req);
|
requests.Add(req);
|
||||||
}
|
}
|
||||||
@@ -195,15 +196,23 @@ namespace ClientServerLib
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lock (requests)
|
try
|
||||||
{
|
{
|
||||||
while (requests.Count > 0)
|
while (requests.Count > 0)
|
||||||
{
|
{
|
||||||
SRequest res = HandleRequest(requests[0]);
|
SRequest res = HandleRequest(requests[0]);
|
||||||
responses.Add(res);
|
lock (responses)
|
||||||
requests.RemoveAt(0);
|
{
|
||||||
|
responses.Add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (mutexRequests)
|
||||||
|
{
|
||||||
|
requests.RemoveAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch { };
|
||||||
|
|
||||||
lock (responses)
|
lock (responses)
|
||||||
{
|
{
|
||||||
@@ -236,7 +245,16 @@ namespace ClientServerLib
|
|||||||
RaiseOnSend(request.Command);
|
RaiseOnSend(request.Command);
|
||||||
byte[] encrypted = connection.Encrypt(request.Command);
|
byte[] encrypted = connection.Encrypt(request.Command);
|
||||||
|
|
||||||
clientStream.Write(encrypted, 0, encrypted.Length);
|
int sendBytes = 0;
|
||||||
|
while(sendBytes < encrypted.Length)
|
||||||
|
{
|
||||||
|
int bytesToSend = encrypted.Length - sendBytes;
|
||||||
|
if (bytesToSend > bufferLength)
|
||||||
|
bytesToSend = bufferLength;
|
||||||
|
|
||||||
|
clientStream.Write(encrypted, sendBytes, bytesToSend);
|
||||||
|
sendBytes += bytesToSend;
|
||||||
|
}
|
||||||
clientStream.Flush();
|
clientStream.Flush();
|
||||||
|
|
||||||
byte[] data = new byte[bufferLength];
|
byte[] data = new byte[bufferLength];
|
||||||
@@ -257,8 +275,9 @@ namespace ClientServerLib
|
|||||||
int messageLength = BitConverter.ToInt32(data, 0);
|
int messageLength = BitConverter.ToInt32(data, 0);
|
||||||
while (messageLength > bytesRead)
|
while (messageLength > bytesRead)
|
||||||
{
|
{
|
||||||
Array.Resize<byte>(ref data, data.Length + bufferLength);
|
if (data.Length < messageLength + bufferLength)
|
||||||
bytesRead += clientStream.Read(data, data.Length - bufferLength, bufferLength);
|
Array.Resize<byte>(ref data, messageLength + bufferLength);
|
||||||
|
bytesRead += clientStream.Read(data, bytesRead, bufferLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypted = new byte[bytesRead];
|
encrypted = new byte[bytesRead];
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace ClientServerLib
|
|||||||
public CConnection(TcpClient client, int ConnectionID)
|
public CConnection(TcpClient client, int ConnectionID)
|
||||||
{
|
{
|
||||||
TcpClient = client;
|
TcpClient = client;
|
||||||
|
client.NoDelay = true;
|
||||||
keySet = false;
|
keySet = false;
|
||||||
connectionID = ConnectionID;
|
connectionID = ConnectionID;
|
||||||
encoder = new UTF8Encoding();
|
encoder = new UTF8Encoding();
|
||||||
@@ -125,17 +126,26 @@ namespace ClientServerLib
|
|||||||
byte[] encrypted = new byte[messageLength - 24];
|
byte[] encrypted = new byte[messageLength - 24];
|
||||||
Array.Copy(Data, 24, encrypted, 0, encrypted.Length);
|
Array.Copy(Data, 24, encrypted, 0, encrypted.Length);
|
||||||
|
|
||||||
using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
|
try
|
||||||
using (var memoryStream = new MemoryStream())
|
|
||||||
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write))
|
|
||||||
{
|
{
|
||||||
cryptoStream.Write(encrypted, 0, encrypted.Length);
|
using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
|
||||||
cryptoStream.FlushFinalBlock();
|
using (var memoryStream = new MemoryStream())
|
||||||
cryptoStream.Close();
|
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write))
|
||||||
byte[] decrypted = memoryStream.ToArray();
|
{
|
||||||
byte[] message = new byte[dataLength];
|
cryptoStream.Write(encrypted, 0, encrypted.Length);
|
||||||
Array.Copy(decrypted, message, dataLength);
|
cryptoStream.FlushFinalBlock();
|
||||||
return message;
|
cryptoStream.Close();
|
||||||
|
|
||||||
|
byte[] decrypted = memoryStream.ToArray();
|
||||||
|
byte[] message = new byte[dataLength];
|
||||||
|
Array.Copy(decrypted, message, dataLength);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,8 +146,9 @@ namespace ClientServerLib
|
|||||||
int messageLength = BitConverter.ToInt32(data, 0);
|
int messageLength = BitConverter.ToInt32(data, 0);
|
||||||
while (messageLength > bytesRead)
|
while (messageLength > bytesRead)
|
||||||
{
|
{
|
||||||
Array.Resize<byte>(ref data, data.Length + bufferLength);
|
if (data.Length < messageLength + bufferLength)
|
||||||
bytesRead += clientStream.Read(data, data.Length - bufferLength, bufferLength);
|
Array.Resize<byte>(ref data, messageLength + bufferLength);
|
||||||
|
bytesRead += clientStream.Read(data, bytesRead, bufferLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] message = new byte[bytesRead];
|
byte[] message = new byte[bytesRead];
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ namespace Vocaluxe.Base.Server
|
|||||||
public static class CCommands
|
public static class CCommands
|
||||||
{
|
{
|
||||||
private static UTF8Encoding encoder = new UTF8Encoding();
|
private static UTF8Encoding encoder = new UTF8Encoding();
|
||||||
|
|
||||||
public static SHA256Managed SHA256 = new SHA256Managed();
|
public static SHA256Managed SHA256 = new SHA256Managed();
|
||||||
|
|
||||||
|
#region Commands
|
||||||
public const int ResponseOK = 1;
|
public const int ResponseOK = 1;
|
||||||
public const int ResponseNOK = 2;
|
public const int ResponseNOK = 2;
|
||||||
|
|
||||||
@@ -39,6 +39,10 @@ namespace Vocaluxe.Base.Server
|
|||||||
public const int ComamndSendMouseMBUpEvent = 241;
|
public const int ComamndSendMouseMBUpEvent = 241;
|
||||||
public const int CommandSendMouseWheelEvent = 250;
|
public const int CommandSendMouseWheelEvent = 250;
|
||||||
|
|
||||||
|
public const int CommandSendAvatarPicture = 500;
|
||||||
|
public const int CommandSendAvatarPictureJpg = 501;
|
||||||
|
#endregion Commands
|
||||||
|
|
||||||
#region General
|
#region General
|
||||||
public static byte[] CreateCommandWithoutParams(int Command)
|
public static byte[] CreateCommandWithoutParams(int Command)
|
||||||
{
|
{
|
||||||
@@ -65,7 +69,36 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#endregion Keyboard
|
#endregion Keyboard
|
||||||
|
|
||||||
|
#region Avatar
|
||||||
|
public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data)
|
||||||
|
{
|
||||||
|
SAvatarPicture ap = new SAvatarPicture();
|
||||||
|
ap.Height = Height;
|
||||||
|
ap.Width = Width;
|
||||||
|
ap.data = new byte[data.Length];
|
||||||
|
Array.Copy(data, ap.data, data.Length);
|
||||||
|
|
||||||
|
return Serialize<SAvatarPicture>(CommandSendAvatarPicture, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool DecodeCommandSendAvatarPicture(byte[] Message, out SAvatarPicture AvatarPicture)
|
||||||
|
{
|
||||||
|
return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] data)
|
||||||
|
{
|
||||||
|
SAvatarPicture ap = new SAvatarPicture();
|
||||||
|
ap.Height = 0;
|
||||||
|
ap.Width = 0;
|
||||||
|
ap.data = new byte[data.Length];
|
||||||
|
Array.Copy(data, ap.data, data.Length);
|
||||||
|
|
||||||
|
return Serialize<SAvatarPicture>(CommandSendAvatarPictureJpg, ap);
|
||||||
|
}
|
||||||
|
#endregion Avatar
|
||||||
|
|
||||||
|
#region Serializing
|
||||||
private static byte[] Serialize<T>(int Command, T obj)
|
private static byte[] Serialize<T>(int Command, T obj)
|
||||||
{
|
{
|
||||||
byte[] command = BitConverter.GetBytes(Command);
|
byte[] command = BitConverter.GetBytes(Command);
|
||||||
@@ -108,5 +141,6 @@ namespace Vocaluxe.Base.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion Serializing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,11 @@ namespace Vocaluxe.Base.Server
|
|||||||
{
|
{
|
||||||
public byte[] SHA256;
|
public byte[] SHA256;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct SAvatarPicture
|
||||||
|
{
|
||||||
|
public int Width;
|
||||||
|
public int Height;
|
||||||
|
public byte[] data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+14
@@ -47,6 +47,7 @@
|
|||||||
this.btRight = new System.Windows.Forms.Button();
|
this.btRight = new System.Windows.Forms.Button();
|
||||||
this.btUp = new System.Windows.Forms.Button();
|
this.btUp = new System.Windows.Forms.Button();
|
||||||
this.btDown = new System.Windows.Forms.Button();
|
this.btDown = new System.Windows.Forms.Button();
|
||||||
|
this.btSendAvatar = new System.Windows.Forms.Button();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -227,11 +228,23 @@
|
|||||||
this.btDown.UseVisualStyleBackColor = true;
|
this.btDown.UseVisualStyleBackColor = true;
|
||||||
this.btDown.Click += new System.EventHandler(this.btDown_Click);
|
this.btDown.Click += new System.EventHandler(this.btDown_Click);
|
||||||
//
|
//
|
||||||
|
// btSendAvatar
|
||||||
|
//
|
||||||
|
this.btSendAvatar.Enabled = false;
|
||||||
|
this.btSendAvatar.Location = new System.Drawing.Point(831, 310);
|
||||||
|
this.btSendAvatar.Name = "btSendAvatar";
|
||||||
|
this.btSendAvatar.Size = new System.Drawing.Size(165, 23);
|
||||||
|
this.btSendAvatar.TabIndex = 14;
|
||||||
|
this.btSendAvatar.Text = "Send Avatar";
|
||||||
|
this.btSendAvatar.UseVisualStyleBackColor = true;
|
||||||
|
this.btSendAvatar.Click += new System.EventHandler(this.btSendAvatar_Click);
|
||||||
|
//
|
||||||
// ClientTest
|
// ClientTest
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1008, 550);
|
this.ClientSize = new System.Drawing.Size(1008, 550);
|
||||||
|
this.Controls.Add(this.btSendAvatar);
|
||||||
this.Controls.Add(this.btDown);
|
this.Controls.Add(this.btDown);
|
||||||
this.Controls.Add(this.btUp);
|
this.Controls.Add(this.btUp);
|
||||||
this.Controls.Add(this.btRight);
|
this.Controls.Add(this.btRight);
|
||||||
@@ -279,6 +292,7 @@
|
|||||||
private System.Windows.Forms.Button btRight;
|
private System.Windows.Forms.Button btRight;
|
||||||
private System.Windows.Forms.Button btUp;
|
private System.Windows.Forms.Button btUp;
|
||||||
private System.Windows.Forms.Button btDown;
|
private System.Windows.Forms.Button btDown;
|
||||||
|
private System.Windows.Forms.Button btSendAvatar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +118,7 @@ namespace ClientTest
|
|||||||
btDown.Enabled = true;
|
btDown.Enabled = true;
|
||||||
btLeft.Enabled = true;
|
btLeft.Enabled = true;
|
||||||
btRight.Enabled = true;
|
btRight.Enabled = true;
|
||||||
|
btSendAvatar.Enabled = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -134,6 +135,7 @@ namespace ClientTest
|
|||||||
btDown.Enabled = false;
|
btDown.Enabled = false;
|
||||||
btLeft.Enabled = false;
|
btLeft.Enabled = false;
|
||||||
btRight.Enabled = false;
|
btRight.Enabled = false;
|
||||||
|
btSendAvatar.Enabled = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,9 +146,12 @@ namespace ClientTest
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
string text = String.Empty;
|
string text = String.Empty;
|
||||||
foreach (byte b in Message)
|
int max = Message.Length;
|
||||||
|
if (max > 1000)
|
||||||
|
max = 1000;
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
{
|
{
|
||||||
text += b.ToString() + " ";
|
text += Message[i].ToString() + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Invoke((MethodInvoker)delegate
|
this.Invoke((MethodInvoker)delegate
|
||||||
@@ -161,9 +166,12 @@ namespace ClientTest
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
string text = String.Empty;
|
string text = String.Empty;
|
||||||
foreach (byte b in Message)
|
int max = Message.Length;
|
||||||
|
if (max > 1000)
|
||||||
|
max = 1000;
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
{
|
{
|
||||||
text += b.ToString() + " ";
|
text += Message[i].ToString() + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Invoke((MethodInvoker)delegate
|
this.Invoke((MethodInvoker)delegate
|
||||||
@@ -203,5 +211,18 @@ namespace ClientTest
|
|||||||
|
|
||||||
client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyRight), null);
|
client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyRight), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btSendAvatar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!client.Connected || !loggedIn)
|
||||||
|
return;
|
||||||
|
|
||||||
|
byte[] data = new byte[512 * 512 * 4];
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
data[i] = (byte) (i % 255);
|
||||||
|
}
|
||||||
|
client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -58,7 +58,6 @@ namespace Vocaluxe.Base
|
|||||||
_Settings.Encoding = Encoding.UTF8;
|
_Settings.Encoding = Encoding.UTF8;
|
||||||
_Settings.ConformanceLevel = ConformanceLevel.Document;
|
_Settings.ConformanceLevel = ConformanceLevel.Document;
|
||||||
|
|
||||||
LoadAvatars();
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +99,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
public static void LoadProfiles()
|
public static void LoadProfiles()
|
||||||
{
|
{
|
||||||
|
LoadAvatars();
|
||||||
_Profiles = new List<SProfile>();
|
_Profiles = new List<SProfile>();
|
||||||
List<string> files = new List<string>();
|
List<string> files = new List<string>();
|
||||||
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
|
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
|
||||||
@@ -128,7 +128,6 @@ namespace Vocaluxe.Base
|
|||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
STexture tex = CDraw.AddTexture(file);
|
STexture tex = CDraw.AddTexture(file);
|
||||||
|
|
||||||
if (tex.Index != -1)
|
if (tex.Index != -1)
|
||||||
{
|
{
|
||||||
SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)};
|
SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)};
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
@@ -39,11 +43,13 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
private static byte[] RequestHandler(int ConnectionID, byte[] Message)
|
private static byte[] RequestHandler(int ConnectionID, byte[] Message)
|
||||||
{
|
{
|
||||||
|
byte[] answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK);
|
||||||
|
|
||||||
if (Message == null)
|
if (Message == null)
|
||||||
return null;
|
return answer;
|
||||||
|
|
||||||
if (Message.Length < 4)
|
if (Message.Length < 4)
|
||||||
return null;
|
return answer;
|
||||||
|
|
||||||
bool loggedIn = false;
|
bool loggedIn = false;
|
||||||
lock (_Clients)
|
lock (_Clients)
|
||||||
@@ -58,8 +64,6 @@ namespace Vocaluxe.Base.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
int command = BitConverter.ToInt32(Message, 0);
|
int command = BitConverter.ToInt32(Message, 0);
|
||||||
byte[] answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK); ;
|
|
||||||
|
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case CCommands.CommandLogin:
|
case CCommands.CommandLogin:
|
||||||
@@ -107,6 +111,64 @@ namespace Vocaluxe.Base.Server
|
|||||||
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Right));
|
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Right));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CCommands.CommandSendAvatarPicture:
|
||||||
|
|
||||||
|
SAvatarPicture avatarPicture;
|
||||||
|
if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPicture))
|
||||||
|
{
|
||||||
|
Bitmap bmp = null;
|
||||||
|
bool success = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bmp = new Bitmap(avatarPicture.Width, avatarPicture.Height);
|
||||||
|
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||||
|
Marshal.Copy(avatarPicture.data, 0, bmpData.Scan0, avatarPicture.data.Length);
|
||||||
|
bmp.UnlockBits(bmpData);
|
||||||
|
|
||||||
|
const string filename = "snapshot";
|
||||||
|
int i = 0;
|
||||||
|
while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png")))
|
||||||
|
i++;
|
||||||
|
bmp.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (bmp != null)
|
||||||
|
bmp.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CCommands.CommandSendAvatarPictureJpg:
|
||||||
|
|
||||||
|
SAvatarPicture avatarPictureJpg;
|
||||||
|
if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPictureJpg))
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
|
||||||
|
int i = 0;
|
||||||
|
while (File.Exists(filename + i + ".jpg"))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
FileStream fs = File.Create(filename + i + ".jpg");
|
||||||
|
fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length);
|
||||||
|
fs.Flush();
|
||||||
|
fs.Close();
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ namespace Vocaluxe.Screens
|
|||||||
_SelectSlides[_SelectSlideDifficulty].SetValues<EGameDifficulty>(0);
|
_SelectSlides[_SelectSlideDifficulty].SetValues<EGameDifficulty>(0);
|
||||||
_SelectSlides[_SelectSlideGuestProfile].SetValues<EOffOn>(0);
|
_SelectSlides[_SelectSlideGuestProfile].SetValues<EOffOn>(0);
|
||||||
_SelectSlides[_SelectSlideActive].SetValues<EOffOn>(0);
|
_SelectSlides[_SelectSlideActive].SetValues<EOffOn>(0);
|
||||||
|
_Statics[_StaticAvatar].Aspect = EAspect.Crop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleInput(SKeyEvent keyEvent)
|
public override bool HandleInput(SKeyEvent keyEvent)
|
||||||
@@ -315,7 +316,6 @@ namespace Vocaluxe.Screens
|
|||||||
if (_Snapshot == null)
|
if (_Snapshot == null)
|
||||||
CWebcam.GetFrame(ref _WebcamTexture);
|
CWebcam.GetFrame(ref _WebcamTexture);
|
||||||
|
|
||||||
_Statics[_StaticAvatar].Aspect = EAspect.Crop;
|
|
||||||
_Statics[_StaticAvatar].Texture = _WebcamTexture;
|
_Statics[_StaticAvatar].Texture = _WebcamTexture;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user