Merge branch 'develop' of github.com:Vocaluxe/Vocaluxe into develop

This commit is contained in:
Florian Küpper committed 2013-05-10 17:25:52 +02:00
commit 3f46acd06e
32 files changed
+1405 -447

No files matched your search

@@ -76,6 +76,9 @@
<Compile Include="..\ClientServerLib\Vocaluxe\VocaluxeStructs.cs">
<Link>ClientServerLib\Vocaluxe\VocaluxeStructs.cs</Link>
</Compile>
<Compile Include="..\ClientServerLib\CDiscover.cs">
<Link>ClientServerLib\CDiscover.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
+46 -22
View File
@@ -16,15 +16,14 @@ using Vocaluxe.Base.Server;
namespace AndroidRemote
{
[Activity (Label = "Vocaluxe Remote", MainLauncher = true)]
[Activity (Label = "Vocaluxe Remote", MainLauncher = true, ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation)]
public class Activity1 : Activity
{
CClient client = new CClient();
Button bConnect;
Button bLogin;
Button bUp;
Button bDown;
Button bSendAvatar;
Button bSendProfile;
bool loggedIn;
byte[] fileBytes;
@@ -32,6 +31,8 @@ namespace AndroidRemote
Java.IO.File file;
Java.IO.File dir;
System.IO.FileStream fs;
bool sendProfile;
protected override void OnCreate (Bundle bundle)
{
@@ -47,21 +48,14 @@ namespace AndroidRemote
bLogin = FindViewById<Button> (Resource.Id.btLogin);
bLogin.Click += delegate { Login(); };
bUp = FindViewById<Button> (Resource.Id.btUp);
bUp.Click += delegate {
client.SendMessage (CCommands.CreateCommandWithoutParams (CCommands.CommandSendKeyUp), OnResponse);
};
bDown = FindViewById<Button> (Resource.Id.btDown);
bDown.Click += delegate {
client.SendMessage (CCommands.CreateCommandWithoutParams (CCommands.CommandSendKeyDown), OnResponse);
};
imageView = FindViewById<ImageView>(Resource.Id.imageView1);
bSendAvatar = FindViewById<Button> (Resource.Id.btSendAvatar);
bSendAvatar.Click += SendAvatar;
bSendProfile = FindViewById<Button> (Resource.Id.btSendProfile);
bSendProfile.Click += SendProfile;
sendProfile = false;
}
protected override void OnStop ()
@@ -92,7 +86,19 @@ namespace AndroidRemote
fs.Flush();
fs.Close();
client.SendMessage (CCommands.CreateCommandSendAvatarPictureJpg(fileBytes), OnResponse);
if (sendProfile)
{
sendProfile = false;
TextView tv = FindViewById<TextView>(Resource.Id.tbPlayerName);
if (tv.Text == String.Empty)
return;
client.SendMessage (CCommands.CreateCommandSendProfile(fileBytes, tv.Text, 0), OnResponse);
}
else
client.SendMessage (CCommands.CreateCommandSendAvatarPictureJpg(fileBytes), OnResponse);
}
private bool IsThereAnAppToTakePictures()
@@ -118,6 +124,12 @@ namespace AndroidRemote
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
StartActivityForResult(intent, 0);
}
private void SendProfile(object sender, EventArgs eventArgs)
{
sendProfile = true;
SendAvatar(sender, eventArgs);
}
private void Connect()
{
@@ -152,16 +164,24 @@ namespace AndroidRemote
switch (command)
{
case CCommands.ResponseLoginFailed:
RunOnUiThread (() => Toast.MakeText(this, "Login Failed", ToastLength.Short).Show());
RunOnUiThread (() => Toast.MakeText(this, Resources.GetString(Resource.String.message_login_failed), ToastLength.Short).Show());
break;
case CCommands.ResponseLoginWrongPassword:
RunOnUiThread (() => Toast.MakeText(this, "Wrong Password", ToastLength.Short).Show());
RunOnUiThread (() => Toast.MakeText(this, Resources.GetString(Resource.String.message_wrong_password), ToastLength.Short).Show());
break;
case CCommands.ResponseLoginOK:
RunOnUiThread (() => UpdateLoginStatus(true));
break;
case CCommands.ResponseOK:
RunOnUiThread (() => Toast.MakeText(this, Resources.GetString(Resource.String.message_ok), ToastLength.Short).Show());
break;
case CCommands.ResponseNOK:
RunOnUiThread (() => Toast.MakeText(this, Resources.GetString(Resource.String.message_nok), ToastLength.Short).Show());
break;
default:
break;
@@ -182,8 +202,8 @@ namespace AndroidRemote
bLogin.Enabled = false;
bLogin.Text = Resources.GetString(Resource.String.button_login);
bConnect.Text = Resources.GetString(Resource.String.button_connect);
bUp.Enabled = false;
bDown.Enabled = false;
bSendAvatar.Enabled = false;
bSendProfile.Enabled = false;
Toast.MakeText(this, Resources.GetString(Resource.String.message_disconnected), ToastLength.Short).Show();
}
}
@@ -194,13 +214,17 @@ namespace AndroidRemote
if (LoggedIn)
{
bUp.Enabled = LoggedIn;
bDown.Enabled = LoggedIn;
bLogin.Text = Resources.GetString(Resource.String.button_logout);
Toast.MakeText(this, "Logged In", ToastLength.Short).Show();
bSendAvatar.Enabled = true;
bSendProfile.Enabled = true;
}
else
{
Toast.MakeText(this, "Not Logged In", ToastLength.Short).Show();
bSendAvatar.Enabled = false;
bSendProfile.Enabled = false;
}
}
}
+39 -27
View File
@@ -66,20 +66,14 @@ namespace AndroidRemote
// aapt resource value: 0x7f060002
public const int btConnect = 2131099650;
// aapt resource value: 0x7f060007
public const int btDown = 2131099655;
// aapt resource value: 0x7f060005
public const int btLogin = 2131099653;
// aapt resource value: 0x7f060008
public const int btSendAvatar = 2131099656;
// aapt resource value: 0x7f060006
public const int btUp = 2131099654;
public const int btSendAvatar = 2131099654;
// aapt resource value: 0x7f060009
public const int imageView1 = 2131099657;
public const int btSendProfile = 2131099657;
// aapt resource value: 0x7f060001
public const int tbIP = 2131099649;
@@ -87,12 +81,18 @@ namespace AndroidRemote
// aapt resource value: 0x7f060004
public const int tbPassword = 2131099652;
// aapt resource value: 0x7f060008
public const int tbPlayerName = 2131099656;
// aapt resource value: 0x7f060000
public const int textView1 = 2131099648;
// aapt resource value: 0x7f060003
public const int textView2 = 2131099651;
// aapt resource value: 0x7f060007
public const int textView3 = 2131099655;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
@@ -134,44 +134,56 @@ namespace AndroidRemote
// aapt resource value: 0x7f040002
public const int button_disconnect = 2130968578;
// aapt resource value: 0x7f040006
public const int button_down = 2130968582;
// aapt resource value: 0x7f040003
public const int button_login = 2130968579;
// aapt resource value: 0x7f040004
public const int button_logout = 2130968580;
// aapt resource value: 0x7f040007
public const int button_send_avatar = 2130968583;
// aapt resource value: 0x7f040005
public const int button_up = 2130968581;
public const int button_send_avatar = 2130968581;
// aapt resource value: 0x7f04000e
public const int ip_address = 2130968590;
// aapt resource value: 0x7f040006
public const int button_send_profile = 2130968582;
// aapt resource value: 0x7f040012
public const int ip_address = 2130968594;
// aapt resource value: 0x7f040007
public const int message_connected = 2130968583;
// aapt resource value: 0x7f040008
public const int message_connected = 2130968584;
public const int message_disconnected = 2130968584;
// aapt resource value: 0x7f040009
public const int message_disconnected = 2130968585;
public const int message_logged_in = 2130968585;
// aapt resource value: 0x7f04000a
public const int message_logged_in = 2130968586;
public const int message_logged_out = 2130968586;
// aapt resource value: 0x7f04000b
public const int message_logged_out = 2130968587;
public const int message_login_failed = 2130968587;
// aapt resource value: 0x7f04000f
public const int password = 2130968591;
// aapt resource value: 0x7f04000c
public const int text_ip_address = 2130968588;
// aapt resource value: 0x7f04000e
public const int message_nok = 2130968590;
// aapt resource value: 0x7f04000d
public const int text_password = 2130968589;
public const int message_ok = 2130968589;
// aapt resource value: 0x7f04000c
public const int message_wrong_password = 2130968588;
// aapt resource value: 0x7f040013
public const int password = 2130968595;
// aapt resource value: 0x7f04000f
public const int text_ip_address = 2130968591;
// aapt resource value: 0x7f040010
public const int text_password = 2130968592;
// aapt resource value: 0x7f040011
public const int text_player_name = 2130968593;
static String()
{
@@ -37,27 +37,26 @@
android:layout_height="wrap_content"
android:id="@+id/btLogin"
android:enabled="false" />
<Button
android:text="@string/button_up"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btUp"
android:enabled="false" />
<Button
android:text="@string/button_down"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btDown"
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:enabled="false" />
<TextView
android:text="@string/text_player_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />
android:layout_height="wrap_content"
android:id="@+id/textView3" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tbPlayerName" />
<Button
android:text="@string/button_send_profile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btSendProfile"
android:enabled="false" />
</LinearLayout>
@@ -5,15 +5,19 @@
<string name="button_disconnect">Disconnect</string>
<string name="button_login">Login</string>
<string name="button_logout">Logout</string>
<string name="button_up">Up</string>
<string name="button_down">Down</string>
<string name="button_send_avatar">Send Avatar Picture</string>
<string name="button_send_profile">Send Profile</string>
<string name="message_connected">Connected</string>
<string name="message_disconnected">Disconnected</string>
<string name="message_logged_in">Logged in</string>
<string name="message_logged_out">Logged out</string>
<string name="message_login_failed">Login failed</string>
<string name="message_wrong_password">Wrong Password</string>
<string name="message_ok">Success</string>
<string name="message_nok">Error</string>
<string name="text_ip_address">IP Address of Vocaluxe Server:</string>
<string name="text_password">Password:</string>
<string name="text_player_name">Player Name:</string>
<string name="ip_address">192.168.178.57</string>
<string name="password">vocaluxe</string>
</resources>
+71 -18
View File
@@ -13,6 +13,7 @@ namespace ClientServerLib
internal class CConnection
{
private bool keySet;
private bool encryption;
private CDiffieHellman dh;
private UTF8Encoding encoder;
private int connectionID;
@@ -29,17 +30,23 @@ namespace ClientServerLib
get { return connectionID; }
}
public CConnection(TcpClient client, int ConnectionID)
public CConnection(TcpClient client, int ConnectionID, bool Encryption = false)
{
TcpClient = client;
client.NoDelay = true;
keySet = false;
encryption = Encryption;
connectionID = ConnectionID;
encoder = new UTF8Encoding();
}
public byte[] GetKeyParams()
{
if (!encryption)
{
return encoder.GetBytes("NO ENCRYPTION");
}
if (dh == null)
dh = new CDiffieHellman(256).GenerateRequest();
@@ -51,34 +58,65 @@ namespace ClientServerLib
if (serverParam == null)
return null;
dh = new CDiffieHellman(256).GenerateResponse(
encoder.GetString(serverParam, 0, serverParam.Length));
string response = encoder.GetString(serverParam, 0, serverParam.Length);
if (response == "NO ENCRYPTION")
{
encryption = false;
keySet = true;
return encoder.GetBytes(response);
}
dh = new CDiffieHellman(256).GenerateResponse(response);
keySet = true;
encryption = true;
return encoder.GetBytes(dh.ToString());
}
public void CreateServerKey(byte[] clientResponse)
{
string response = encoder.GetString(clientResponse, 0, clientResponse.Length);
if (response == "NO ENCRYPTION")
{
keySet = true;
return;
}
if (dh == null)
return;
dh.HandleResponse(encoder.GetString(clientResponse, 0, clientResponse.Length));
dh.HandleResponse(response);
keySet = true;
}
public byte[] Encrypt(byte[] Data)
{
if (Data == null || !keySet)
if (Data == null || (!keySet && encryption))
return Data;
byte[] dataLength = BitConverter.GetBytes(Data.Length);
if (!encryption)
{
int len = 4 + dataLength.Length + Data.Length;
byte[] messageLength = BitConverter.GetBytes(len);
using (var stream = new MemoryStream())
{
stream.Write(messageLength, 0, messageLength.Length);
stream.Write(dataLength, 0, dataLength.Length);
stream.Write(Data, 0, Data.Length);
return stream.ToArray();
}
}
using (Aes aes = new AesManaged())
{
aes.Key = dh.Key;
aes.GenerateIV();
byte[] dataLength = BitConverter.GetBytes(Data.Length);
using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))
using (var memoryStream = new MemoryStream())
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
@@ -91,32 +129,47 @@ namespace ClientServerLib
int len = 4 + aes.IV.Length + dataLength.Length + encrypted.Length;
byte[] messageLength = BitConverter.GetBytes(len);
MemoryStream stream = new MemoryStream();
stream.Write(messageLength, 0, messageLength.Length);
stream.Write(aes.IV, 0, aes.IV.Length);
stream.Write(dataLength, 0, dataLength.Length);
stream.Write(encrypted, 0, encrypted.Length);
using (var stream = new MemoryStream())
{
stream.Write(messageLength, 0, messageLength.Length);
stream.Write(aes.IV, 0, aes.IV.Length);
stream.Write(dataLength, 0, dataLength.Length);
stream.Write(encrypted, 0, encrypted.Length);
return stream.ToArray();
return stream.ToArray();
}
}
}
}
public byte[] Decrypt(byte[] Data)
{
if (Data == null || !keySet)
if (Data == null || (!keySet && encryption))
return Data;
if (Data.Length < 25)
return null;
int messageLength = BitConverter.ToInt32(Data, 0);
if (messageLength > Data.Length)
return null;
int dataLength;
if (!encryption)
{
dataLength = BitConverter.ToInt32(Data, 4);
byte[] message = new byte[dataLength];
Array.Copy(Data, 8, message, 0, dataLength);
return message;
}
if (Data.Length < 25)
return null;
byte[] IV = new byte[16];
Array.Copy(Data, 4, IV, 0, 16);
int dataLength = BitConverter.ToInt32(Data, 20);
dataLength = BitConverter.ToInt32(Data, 20);
using (Aes aes = new AesManaged())
{
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Timers;
namespace ClientServerLib
{
public delegate void OnServerDiscovered(string IPAddress, string Hostname);
public class CDiscover
{
private string _Keyword;
private string _BroadcastAddress;
private int _Port;
private Thread _DiscoverThread;
private bool _DiscoverRunning;
private OnServerDiscovered _OnDiscovered;
private System.Timers.Timer _BroadcastTimer;
public CDiscover(int Port, string Keyword, string BroadcastAddress = "255.255.255.255")
{
_BroadcastAddress = BroadcastAddress;
_Port = Port;
_Keyword = Keyword;
_DiscoverRunning = false;
_BroadcastTimer = new System.Timers.Timer();
_BroadcastTimer.Elapsed += new ElapsedEventHandler(OnBroadcastEvent);
_BroadcastTimer.Interval = 2500;
}
public void StartBroadcasting()
{
_BroadcastTimer.Start();
}
public void Stop()
{
_BroadcastTimer.Stop();
_DiscoverRunning = false;
}
public void Discover(OnServerDiscovered OnDiscovered, int Timeout = 5000)
{
if (_DiscoverRunning)
return;
_DiscoverRunning = true;
_DiscoverThread = new Thread(() => _Discover(Timeout));
_OnDiscovered = OnDiscovered;
_DiscoverThread.Start();
}
private void OnBroadcastEvent(object source, ElapsedEventArgs e)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
s.EnableBroadcast = true;
IPAddress broadcast = IPAddress.Parse(_BroadcastAddress);
byte[] sendbuf = Encoding.UTF8.GetBytes(_Keyword);
IPEndPoint ep = new IPEndPoint(broadcast, _Port);
s.SendTo(sendbuf, ep);
s.Close();
}
private void _Discover(int Timeout)
{
UdpClient listener = null;
Stopwatch timer = new Stopwatch();
List<string> knownServer = new List<string>();
bool foundSomething = false;
timer.Start();
while (_DiscoverRunning && timer.ElapsedMilliseconds < Timeout * 2)
{
try
{
listener = new UdpClient(_Port);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, _Port);
listener.Client.ReceiveTimeout = Timeout;
byte[] bytes = listener.Receive(ref groupEP);
string message = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
foundSomething = true;
if (!knownServer.Contains(groupEP.Address.ToString()))
{
knownServer.Add(groupEP.Address.ToString());
if (_OnDiscovered != null)
{
IPHostEntry e = Dns.GetHostEntry(groupEP.Address);
string hostname = e.HostName;
_OnDiscovered(groupEP.Address.ToString(), hostname);
}
}
listener.Close();
}
catch (Exception)
{
if (listener != null)
listener.Close();
}
}
_DiscoverRunning = false;
if (!foundSomething)
_OnDiscovered("Timeout", "unknown");
}
}
}
+4 -2
View File
@@ -13,6 +13,7 @@ namespace ClientServerLib
private TcpListener tcpListener;
private Thread listenThread;
private int port;
private bool encryption;
private int bufferLength = 8192;
private bool running;
@@ -21,11 +22,12 @@ namespace ClientServerLib
private Dictionary<int, CConnection> clients;
private Queue<int> ids;
public CServer(HandleRequest RequestCallback, int Port = 3000)
public CServer(HandleRequest RequestCallback, int Port = 3000, bool Encryption = false)
{
port = Port;
running = false;
requestCallback = RequestCallback;
encryption = Encryption;
clients = new Dictionary<int, CConnection>();
ids = new Queue<int>(1000);
@@ -90,7 +92,7 @@ namespace ClientServerLib
if (client != null)
{
int id = ids.Dequeue();
CConnection connection = new CConnection(client, id);
CConnection connection = new CConnection(client, id, encryption);
lock (clients)
{
@@ -46,6 +46,7 @@
<ItemGroup>
<Compile Include="CClient.cs" />
<Compile Include="CConnection.cs" />
<Compile Include="CDiscover.cs" />
<Compile Include="CServer.cs" />
<Compile Include="DeffieHellman\BigInt.cs" />
<Compile Include="DeffieHellman\DeffieHellman.cs" />
@@ -14,6 +14,8 @@ namespace Vocaluxe.Base.Server
private static UTF8Encoding encoder = new UTF8Encoding();
public static SHA256Managed SHA256 = new SHA256Managed();
public const string BroadcastKeyword = "I am a Vocaluxe Server";
#region Commands
public const int ResponseOK = 1;
public const int ResponseNOK = 2;
@@ -41,6 +43,9 @@ namespace Vocaluxe.Base.Server
public const int CommandSendAvatarPicture = 500;
public const int CommandSendAvatarPictureJpg = 501;
public const int CommandSendProfile = 510;
#endregion Commands
#region General
@@ -69,7 +74,7 @@ namespace Vocaluxe.Base.Server
#endregion Keyboard
#region Avatar
#region Profiles
public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data)
{
SAvatarPicture ap = new SAvatarPicture();
@@ -86,17 +91,39 @@ namespace Vocaluxe.Base.Server
return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture);
}
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] data)
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] AvatarJpgData)
{
SAvatarPicture ap = new SAvatarPicture();
ap.Height = 0;
ap.Width = 0;
ap.data = new byte[data.Length];
Array.Copy(data, ap.data, data.Length);
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
return Serialize<SAvatarPicture>(CommandSendAvatarPictureJpg, ap);
}
#endregion Avatar
public static byte[] CreateCommandSendProfile(byte[] AvatarJpgData, string PlayerName, int Difficulty)
{
SAvatarPicture ap = new SAvatarPicture();
ap.Height = 0;
ap.Width = 0;
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
SProfile profile = new SProfile();
profile.Avatar = ap;
profile.PlayerName = PlayerName;
profile.Difficulty = Difficulty;
return Serialize<SProfile>(CommandSendProfile, profile);
}
public static bool DecodeCommandSendProfile(byte[] Message, out SProfile Profile)
{
return TryDeserialize<SProfile>(Message, out Profile);
}
#endregion Profiles
#region Serializing
private static byte[] Serialize<T>(int Command, T obj)
@@ -13,4 +13,11 @@ namespace Vocaluxe.Base.Server
public int Height;
public byte[] data;
}
public struct SProfile
{
public SAvatarPicture Avatar;
public string PlayerName;
public int Difficulty;
}
}
+53
View File
@@ -48,6 +48,10 @@
this.btUp = new System.Windows.Forms.Button();
this.btDown = new System.Windows.Forms.Button();
this.btSendAvatar = new System.Windows.Forms.Button();
this.btSendProfile = new System.Windows.Forms.Button();
this.btDiscover = new System.Windows.Forms.Button();
this.tbDiscoveredServer = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
@@ -239,11 +243,56 @@
this.btSendAvatar.UseVisualStyleBackColor = true;
this.btSendAvatar.Click += new System.EventHandler(this.btSendAvatar_Click);
//
// btSendProfile
//
this.btSendProfile.Enabled = false;
this.btSendProfile.Location = new System.Drawing.Point(831, 339);
this.btSendProfile.Name = "btSendProfile";
this.btSendProfile.Size = new System.Drawing.Size(165, 23);
this.btSendProfile.TabIndex = 15;
this.btSendProfile.Text = "Send Profile";
this.btSendProfile.UseVisualStyleBackColor = true;
this.btSendProfile.Click += new System.EventHandler(this.btSendProfile_Click);
//
// btDiscover
//
this.btDiscover.Location = new System.Drawing.Point(831, 502);
this.btDiscover.Name = "btDiscover";
this.btDiscover.Size = new System.Drawing.Size(165, 23);
this.btDiscover.TabIndex = 16;
this.btDiscover.Text = "Discover";
this.btDiscover.UseVisualStyleBackColor = true;
this.btDiscover.Click += new System.EventHandler(this.btDiscover_Click);
//
// tbDiscoveredServer
//
this.tbDiscoveredServer.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbDiscoveredServer.Location = new System.Drawing.Point(15, 405);
this.tbDiscoveredServer.Multiline = true;
this.tbDiscoveredServer.Name = "tbDiscoveredServer";
this.tbDiscoveredServer.Size = new System.Drawing.Size(810, 120);
this.tbDiscoveredServer.TabIndex = 17;
this.tbDiscoveredServer.WordWrap = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 389);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 13);
this.label1.TabIndex = 18;
this.label1.Text = "Server:";
//
// ClientTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 550);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbDiscoveredServer);
this.Controls.Add(this.btDiscover);
this.Controls.Add(this.btSendProfile);
this.Controls.Add(this.btSendAvatar);
this.Controls.Add(this.btDown);
this.Controls.Add(this.btUp);
@@ -293,6 +342,10 @@
private System.Windows.Forms.Button btUp;
private System.Windows.Forms.Button btDown;
private System.Windows.Forms.Button btSendAvatar;
private System.Windows.Forms.Button btSendProfile;
private System.Windows.Forms.Button btDiscover;
private System.Windows.Forms.TextBox tbDiscoveredServer;
private System.Windows.Forms.Label label1;
}
}
+60 -1
View File
@@ -3,8 +3,11 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
@@ -16,12 +19,15 @@ namespace ClientTest
public partial class ClientTest : Form
{
CClient client;
CDiscover discover;
private bool loggedIn;
public ClientTest()
{
client = new CClient();
loggedIn = false;
discover = new CDiscover(3000, CCommands.BroadcastKeyword);
InitializeComponent();
}
@@ -29,6 +35,7 @@ namespace ClientTest
protected override void OnClosing(CancelEventArgs e)
{
client.Close();
discover.Stop();
base.OnClosing(e);
}
@@ -119,6 +126,7 @@ namespace ClientTest
btLeft.Enabled = true;
btRight.Enabled = true;
btSendAvatar.Enabled = true;
btSendProfile.Enabled = true;
});
}
else
@@ -136,6 +144,7 @@ namespace ClientTest
btLeft.Enabled = false;
btRight.Enabled = false;
btSendAvatar.Enabled = false;
btSendProfile.Enabled = false;
});
}
}
@@ -222,7 +231,57 @@ namespace ClientTest
{
data[i] = (byte) (i % 255);
}
client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), null);
client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), OnResponse);
}
private void btSendProfile_Click(object sender, EventArgs e)
{
if (!client.Connected || !loggedIn)
return;
if (!File.Exists("test.jpg"))
{
byte[] data = new byte[512 * 512 * 4];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(i % 255);
}
Bitmap bmp = new Bitmap(512, 512);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
bmp.UnlockBits(bmpData);
bmp.Save("test.jpg", ImageFormat.Jpeg);
bmp.Dispose();
}
if (File.Exists("test.jpg"))
{
byte[] data = File.ReadAllBytes("test.jpg");
if (data == null)
return;
client.SendMessage(CCommands.CreateCommandSendProfile(data, "TestUser", 0), OnResponse);
}
}
private void btDiscover_Click(object sender, EventArgs e)
{
tbDiscoveredServer.Text = "Searching for Vocaluxe Server:\r\n";
discover.Discover(_OnDiscovered);
}
private void _OnDiscovered(string Address, string HostName)
{
this.Invoke((MethodInvoker)delegate
{
if (Address != "Timeout")
tbDiscoveredServer.Text += "IP = " + Address + "; HostName = " + HostName + "\r\n";
else
tbDiscoveredServer.Text += "Timeout" + "\r\n";
});
}
}
}
Binary file not shown.
+49 -15
View File
@@ -30,6 +30,7 @@ using Vocaluxe.Lib.Sound;
using Vocaluxe.Lib.Webcam;
using VocaluxeLib;
using VocaluxeLib.Menu;
using VocaluxeLib.Profile;
namespace Vocaluxe.Base
{
@@ -114,7 +115,8 @@ namespace Vocaluxe.Base
public static SWebcamConfig WebcamConfig;
// Server
public static EOffOn Server = EOffOn.TR_CONFIG_ON;
public static EOffOn ServerActive = EOffOn.TR_CONFIG_OFF;
public static EOffOn ServerEncryption = EOffOn.TR_CONFIG_OFF;
public static int ServerPort = 3000;
public static string ServerPassword = "vocaluxe";
@@ -279,6 +281,16 @@ namespace Vocaluxe.Base
xmlReader.TryGetIntValueRange("//root/Record/MicDelay", ref MicDelay, 0, 500);
MicDelay = (int)(20 * Math.Round(MicDelay / 20.0));
#endregion Record
#region Server
xmlReader.TryGetEnumValue("//root/Server/ServerActive", ref ServerActive);
xmlReader.TryGetEnumValue("//root/Server/ServerEncryption", ref ServerEncryption);
xmlReader.TryGetIntValue("//root/Server/ServerPort", ref ServerPort);
if (ServerPort < 1 || ServerPort > 65535)
ServerPort = 3000;
xmlReader.GetValue("//root/Server/ServerPassword", out ServerPassword, ServerPassword);
#endregion Server
}
public static bool SaveConfig()
@@ -361,25 +373,25 @@ namespace Vocaluxe.Base
writer.WriteComment("Name of cover-theme");
writer.WriteElementString("Cover", CoverTheme);
writer.WriteComment("Draw note-lines:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteComment("Draw note-lines: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("DrawNoteLines", Enum.GetName(typeof(EOffOn), DrawNoteLines));
writer.WriteComment("Draw tone-helper:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteComment("Draw tone-helper: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("DrawToneHelper", Enum.GetName(typeof(EOffOn), DrawToneHelper));
writer.WriteComment("Look of timer:" + CHelper.ListStrings(Enum.GetNames(typeof(ETimerLook))));
writer.WriteComment("Look of timer: " + CHelper.ListStrings(Enum.GetNames(typeof(ETimerLook))));
writer.WriteElementString("TimerLook", Enum.GetName(typeof(ETimerLook), TimerLook));
writer.WriteComment("Information about players on SingScreen:" + CHelper.ListStrings(Enum.GetNames(typeof(EPlayerInfo))));
writer.WriteComment("Information about players on SingScreen: " + CHelper.ListStrings(Enum.GetNames(typeof(EPlayerInfo))));
writer.WriteElementString("PlayerInfo", Enum.GetName(typeof(EPlayerInfo), PlayerInfo));
writer.WriteComment("Fade player-information with lyrics and notebars:" + CHelper.ListStrings(Enum.GetNames(typeof(EFadePlayerInfo))));
writer.WriteComment("Fade player-information with lyrics and notebars: " + CHelper.ListStrings(Enum.GetNames(typeof(EFadePlayerInfo))));
writer.WriteElementString("FadePlayerInfo", Enum.GetName(typeof(EFadePlayerInfo), FadePlayerInfo));
writer.WriteComment("Cover Loading:" + CHelper.ListStrings(Enum.GetNames(typeof(ECoverLoading))));
writer.WriteComment("Cover Loading: " + CHelper.ListStrings(Enum.GetNames(typeof(ECoverLoading))));
writer.WriteElementString("CoverLoading", Enum.GetName(typeof(ECoverLoading), CoverLoading));
writer.WriteComment("Lyric Style:" + CHelper.ListStrings(Enum.GetNames(typeof(ELyricStyle))));
writer.WriteComment("Lyric Style: " + CHelper.ListStrings(Enum.GetNames(typeof(ELyricStyle))));
writer.WriteElementString("LyricStyle", Enum.GetName(typeof(ELyricStyle), LyricStyle));
writer.WriteEndElement();
@@ -400,15 +412,16 @@ namespace Vocaluxe.Base
writer.WriteComment("AudioLatency from -500 to 500 ms");
writer.WriteElementString("AudioLatency", AudioLatency.ToString());
writer.WriteComment("Background Music");
writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic));
writer.WriteComment("Background Music Volume from 0 to 100");
writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString());
writer.WriteComment("Background Music Source");
writer.WriteComment("Background Music Source: " + CHelper.ListStrings(Enum.GetNames(typeof(EBackgroundMusicSource))));
writer.WriteElementString("BackgroundMusicSource", Enum.GetName(typeof(EBackgroundMusicSource), BackgroundMusicSource));
writer.WriteComment("Background Music use start-tag of songs");
writer.WriteComment("Background Music use start-tag of songs: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("BackgroundMusicUseStart", Enum.GetName(typeof(EOffOn), BackgroundMusicUseStart));
writer.WriteComment("Preview Volume from 0 to 100");
@@ -538,6 +551,24 @@ namespace Vocaluxe.Base
writer.WriteEndElement();
#endregion Record
#region Server
writer.WriteStartElement("Server");
writer.WriteComment("Server On/Off: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("ServerActive", Enum.GetName(typeof(EOffOn), ServerActive));
writer.WriteComment("Server Encryption On/Off: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("ServerEncryption", Enum.GetName(typeof(EOffOn), ServerEncryption));
writer.WriteComment("Server Port (default: 3000) [1..65535]");
writer.WriteElementString("ServerPort", ServerPort.ToString());
writer.WriteComment("Server Password (default: vocaluxe)");
writer.WriteElementString("ServerPassword", ServerPassword);
writer.WriteEndElement();
#endregion Server
// End of File
writer.WriteEndElement(); //end of root
writer.WriteEndDocument();
@@ -805,17 +836,20 @@ namespace Vocaluxe.Base
/// </summary>
public static void UsePlayers()
{
CProfile[] profiles = CProfiles.GetProfiles();
for (int j = 0; j < CSettings.MaxNumPlayer; j++)
{
CGame.Players[j].ProfileID = -1;
if (Players[j] == "")
if (Players[j] == "" || profiles == null)
continue;
for (int i = 0; i < CProfiles.Profiles.Length; i++)
for (int i = 0; i < profiles.Length; i++)
{
if (Path.GetFileName(CProfiles.Profiles[i].FileName) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON)
if (Path.GetFileName(profiles[i].FileName) == Players[j] && profiles[i].Active == EOffOn.TR_CONFIG_ON)
{
//Update Game-infos with player
CGame.Players[j].ProfileID = i;
CGame.Players[j].ProfileID = profiles[i].ID;
}
}
}
-2
View File
@@ -68,8 +68,6 @@ namespace Vocaluxe.Base
_SongQueue.Init();
Players = new SPlayer[CSettings.MaxNumPlayer];
ResetPlayer();
CConfig.UsePlayers();
}
public static EGameMode GameMode
+1
View File
@@ -322,6 +322,7 @@ namespace Vocaluxe.Base
CSound.Update();
CBackgroundMusic.Update();
CController.Update();
CProfiles.Update();
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
CSongs.LoadCover();
+6 -1
View File
@@ -214,6 +214,11 @@ namespace Vocaluxe.Base
{
return CSettings.MedleyMinDuration;
}
public string GetFolderProfiles()
{
return CSettings.FolderProfiles;
}
}
class CBtheme : ITheme
@@ -549,7 +554,7 @@ namespace Vocaluxe.Base
{
public CProfile[] GetProfiles()
{
return CProfiles.Profiles;
return CProfiles.GetProfiles();
}
public EGameDifficulty GetDifficulty(int profileID)
+488 -151
View File
@@ -28,121 +28,407 @@ using VocaluxeLib.Profile;
namespace Vocaluxe.Base
{
[Flags]
public enum EProfileChangedFlags
{
None = 1,
Avatar = 2,
Profile = 4
}
public delegate void ProfileChangedCallback(EProfileChangedFlags TypeChanged);
static class CProfiles
{
private static List<CProfile> _Profiles;
private static readonly List<CAvatar> _Avatars = new List<CAvatar>();
public static CProfile[] Profiles
#region enums and structs
enum EAction
{
get { return _Profiles.ToArray(); }
LoadProfiles,
LoadAvatars,
AddProfile,
EditProfile,
DeleteProfile,
AddAvatar,
EditAvatar
}
struct SChange
{
public CProfile Profile;
public CAvatar Avatar;
public EAction Action;
public int ProfileID;
}
#endregion enums and structs
#region private vars
private static Dictionary<int, CProfile> _Profiles;
private static Queue<int> _ProfileIDs;
private static Dictionary<int, CAvatar> _Avatars;
private static Queue<int> _AvatarIDs;
private static Queue<SChange> _Queue = new Queue<SChange>();
private static Object _QueueMutex = new Object();
private static List<ProfileChangedCallback> _ProfileChangedCallbacks = new List<ProfileChangedCallback>();
private static bool _ProfilesChanged = false;
private static bool _AvatarsChanged = false;
#endregion private vars
#region properties
public static int NumProfiles
{
get { return _Profiles.Count; }
}
public static CAvatar[] Avatars
{
get { return _Avatars.ToArray(); }
}
public static int NumAvatars
{
get { return _Avatars.Count; }
}
#endregion properties
#region public methods
public static void Init()
{
_Avatars = new Dictionary<int, CAvatar>();
_AvatarIDs = new Queue<int>(1000);
for (int i = 0; i < 1000; i++)
{
_AvatarIDs.Enqueue(i);
}
_Profiles = new Dictionary<int, CProfile>();
_ProfileIDs = new Queue<int>(100);
for (int i = 0; i < 100; i++)
{
_ProfileIDs.Enqueue(i);
}
LoadProfiles();
}
public static string GetPlayerName(int profileID, int playerNum = 0)
public static void Update()
{
if (ICProfileIDValid(profileID))
return _Profiles[profileID].PlayerName;
string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER");
if (playerNum > 0)
playerName += " " + playerNum;
return playerName;
lock (_QueueMutex)
{
while (_Queue.Count > 0)
{
SChange change = _Queue.Dequeue();
switch (change.Action)
{
case EAction.LoadProfiles:
_LoadProfiles();
_ProfilesChanged = true;
_AvatarsChanged = true;
break;
case EAction.LoadAvatars:
_LoadAvatars();
_AvatarsChanged = true;
break;
case EAction.AddProfile:
if (change.Profile == null)
break;
change.Profile.ID = _ProfileIDs.Dequeue();
change.Profile.Avatar = _GetAvatar(change.Profile.AvatarFileName);
change.Profile.SaveProfile();
_Profiles.Add(change.Profile.ID, change.Profile);
_ProfilesChanged = true;
break;
case EAction.EditProfile:
if (change.Profile == null)
break;
if (!ICProfileIDValid(change.Profile.ID))
return;
_Profiles[change.Profile.ID] = change.Profile;
_ProfilesChanged = true;
break;
case EAction.DeleteProfile:
if (!ICProfileIDValid(change.ProfileID))
break;
_DeleteProfile(change.ProfileID);
_ProfilesChanged = true;
break;
case EAction.AddAvatar:
if (change.Avatar == null)
break;
change.Avatar.ID = _AvatarIDs.Dequeue();
_Avatars.Add(change.Avatar.ID, change.Avatar);
_AvatarsChanged = true;
break;
case EAction.EditAvatar:
if (change.Avatar == null)
break;
if (!ICAvatarIDValid(change.Avatar.ID))
return;
_Avatars[change.Avatar.ID] = change.Avatar;
_AvatarsChanged = true;
break;
default:
break;
}
}
}
if (_ProfileChangedCallbacks.Count == 0)
return;
EProfileChangedFlags flags = EProfileChangedFlags.None;
if (_AvatarsChanged)
flags = EProfileChangedFlags.Avatar;
if (_ProfilesChanged)
flags |= EProfileChangedFlags.Profile;
if (flags != EProfileChangedFlags.None)
{
int index = 0;
while (index < _ProfileChangedCallbacks.Count)
{
try
{
_ProfileChangedCallbacks[index](flags);
}
catch (Exception)
{
_ProfileChangedCallbacks.RemoveAt(index);
}
index++;
}
}
_AvatarsChanged = false;
_ProfilesChanged = false;
}
public static void AddProfileChangedCallback(ProfileChangedCallback Notification)
{
_ProfileChangedCallbacks.Add(Notification);
}
public static void LoadProfiles()
{
SChange change = new SChange();
change.Action = EAction.LoadProfiles;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void LoadAvatars()
{
SChange change = new SChange();
change.Action = EAction.LoadAvatars;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void AddProfile(CProfile NewProfile)
{
if (NewProfile == null)
return;
SChange change = new SChange();
change.Action = EAction.AddProfile;
change.Profile = NewProfile;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void EditProfile(CProfile EditProfile)
{
if (EditProfile == null)
return;
SChange change = new SChange();
change.Action = EAction.EditProfile;
change.Profile = EditProfile;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void DeleteProfile(int profileID)
{
if (!ICProfileIDValid(profileID))
return;
SChange change = new SChange();
change.Action = EAction.DeleteProfile;
change.ProfileID = profileID;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void AddAvatar(CAvatar NewAvatar)
{
if (NewAvatar == null)
return;
SChange change = new SChange();
change.Action = EAction.AddAvatar;
change.Avatar = NewAvatar;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static void EditAvatar(CAvatar EditAvatar)
{
if (EditAvatar == null)
return;
SChange change = new SChange();
change.Action = EAction.EditAvatar;
change.Avatar = EditAvatar;
lock (_QueueMutex)
{
_Queue.Enqueue(change);
}
}
public static CProfile[] GetProfiles()
{
List<CProfile> list = new List<CProfile>();
if (_Profiles.Count == 0)
return null;
CProfile[] result = new CProfile[_Profiles.Count];
_Profiles.Values.CopyTo(result, 0);
for (int i = 0; i < result.Length; i++)
{
list.Add(result[i]);
}
list.Sort(_CompareByPlayerName);
return list.ToArray();
}
public static CAvatar[] GetAvatars()
{
CAvatar[] result = null;
if (_Avatars.Count == 0)
return null;
result = new CAvatar[_Avatars.Count];
_Avatars.Values.CopyTo(result, 0);
return result;
}
public static int NewProfile(string fileName = "")
{
CProfile profile = new CProfile
{
PlayerName = String.Empty,
Difficulty = EGameDifficulty.TR_CONFIG_EASY,
Avatar = new CAvatar(-1),
GuestProfile = EOffOn.TR_CONFIG_OFF,
Active = EOffOn.TR_CONFIG_ON,
FileName = fileName != "" ? Path.Combine(CSettings.FolderProfiles, fileName) : String.Empty
};
if (File.Exists(profile.FileName))
return -1;
_Profiles.Add(profile);
return _Profiles.Count - 1;
profile.ID = _ProfileIDs.Dequeue();
_Profiles.Add(profile.ID, profile);
_ProfilesChanged = true;
return profile.ID;
}
public static int NewAvatar(string fileName)
{
CAvatar avatar = new CAvatar(-1);
if (!avatar.LoadFromFile(fileName))
return -1;
avatar.ID = _AvatarIDs.Dequeue();
_Avatars.Add(avatar.ID, avatar);
_AvatarsChanged = true;
return avatar.ID;
}
public static void SaveProfiles()
{
for (int i = 0; i < _Profiles.Count; i++)
_SaveProfile(i);
LoadProfiles();
}
public static void LoadProfiles()
{
LoadAvatars();
_Profiles = new List<CProfile>();
List<string> files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
foreach (string file in files)
_LoadProfile(file);
_SortProfilesByName();
}
public static void LoadAvatars()
{
for (int i = 0; i < _Avatars.Count; i++)
foreach (int id in _Profiles.Keys)
{
STexture texture = _Avatars[i].Texture;
CDraw.RemoveTexture(ref texture);
}
_Avatars.Clear();
List<string> files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true));
foreach (string file in files)
{
STexture tex = CDraw.AddTexture(file);
if (tex.Index != -1)
{
CAvatar avatar = new CAvatar(-1) {Texture = tex, FileName = Path.GetFileName(file)};
_Avatars.Add(avatar);
}
_Profiles[id].SaveProfile();
}
}
public static bool ICProfileIDValid(int profileID)
{
return _Profiles.ContainsKey(profileID);
}
public static bool ICAvatarIDValid(int avatarID)
{
return _Avatars.ContainsKey(avatarID);
}
#endregion public methods
#region profile properties
public static string GetPlayerName(int profileID, int playerNum = 0)
{
if (ICProfileIDValid(profileID))
return _Profiles[profileID].PlayerName;
string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER");
if (playerNum > 0)
playerName += " " + playerNum;
return playerName;
}
public static void SetPlayerName(int profileID, string PlayerName)
{
if (!ICProfileIDValid(profileID))
return;
_Profiles[profileID].PlayerName = PlayerName;
}
public static string GetProfileFileName(int profileID)
{
if (!ICProfileIDValid(profileID))
return String.Empty;
return Path.GetFileName(_Profiles[profileID].FileName);
}
public static string AddGetPlayerName(int profileID, char chr)
{
if (!ICProfileIDValid(profileID))
return String.Empty;
CProfile profile = _Profiles[profileID];
profile.PlayerName += chr;
_Profiles[profileID] = profile;
return profile.PlayerName;
_Profiles[profileID].PlayerName += chr;
return _Profiles[profileID].PlayerName;
}
public static string GetDeleteCharInPlayerName(int profileID)
@@ -153,16 +439,10 @@ namespace Vocaluxe.Base
CProfile profile = _Profiles[profileID];
if (profile.PlayerName != "")
profile.PlayerName = profile.PlayerName.Remove(profile.PlayerName.Length - 1);
_Profiles[profileID] = profile;
return profile.PlayerName;
}
public static bool ICProfileIDValid(int profileID)
{
return profileID >= 0 && profileID < _Profiles.Count;
}
public static EGameDifficulty GetDifficulty(int profileID)
{
return ICProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL;
@@ -173,9 +453,7 @@ namespace Vocaluxe.Base
if (!ICProfileIDValid(profileID))
return;
CProfile profile = _Profiles[profileID];
profile.Difficulty = difficulty;
_Profiles[profileID] = profile;
_Profiles[profileID].Difficulty = difficulty;
}
public static EOffOn GetGuestProfile(int profileID)
@@ -183,28 +461,25 @@ namespace Vocaluxe.Base
return ICProfileIDValid(profileID) ? _Profiles[profileID].GuestProfile : EOffOn.TR_CONFIG_OFF;
}
public static EOffOn GetActive(int profileID)
{
return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF;
}
public static void SetGuestProfile(int profileID, EOffOn option)
{
if (!ICProfileIDValid(profileID))
return;
CProfile profile = _Profiles[profileID];
profile.GuestProfile = option;
_Profiles[profileID] = profile;
_Profiles[profileID].GuestProfile = option;
}
public static EOffOn GetActive(int profileID)
{
return ICProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF;
}
public static void SetActive(int profileID, EOffOn option)
{
if (!ICProfileIDValid(profileID))
return;
CProfile profile = _Profiles[profileID];
profile.Active = option;
_Profiles[profileID] = profile;
_Profiles[profileID].Active = option;
}
public static bool IsGuestProfile(int profileID)
@@ -222,36 +497,134 @@ namespace Vocaluxe.Base
return _Profiles[profileID].Active == EOffOn.TR_CONFIG_ON;
}
public static void SetAvatar(int profileID, int avatarNr)
public static void SetAvatar(int profileID, int avatarID)
{
if (!ICProfileIDValid(profileID) || avatarNr < 0 || avatarNr >= _Avatars.Count)
if (!ICProfileIDValid(profileID) || !ICAvatarIDValid(avatarID))
return;
CProfile profile = _Profiles[profileID];
profile.Avatar = _Avatars[avatarNr];
_Profiles[profileID] = profile;
_Profiles[profileID].Avatar = _Avatars[avatarID];
}
public static int GetAvatarNr(int profileID)
public static int GetAvatarID(int profileID)
{
if (!ICProfileIDValid(profileID))
return 0;
return -1;
for (int i = 0; i < _Avatars.Count; i++)
return _Profiles[profileID].Avatar.ID;
}
#endregion profile properties
#region avatar texture
public static STexture GetAvatarTexture(int avatarID)
{
if (!ICAvatarIDValid(avatarID))
return new STexture(-1);
return _Avatars[avatarID].Texture;
}
public static STexture GetAvatarTextureFromProfile(int profileID)
{
if (!ICProfileIDValid(profileID))
return new STexture(-1);
return _Profiles[profileID].Avatar.Texture;
}
#endregion avatar texture
#region private methods
private static void _LoadProfiles()
{
_LoadAvatars();
List<string> knownFiles = new List<string>();
if (_Profiles.Count > 0)
{
if (_Profiles[profileID].Avatar.FileName == _Avatars[i].FileName)
return i;
int[] ids = new int[_Profiles.Keys.Count];
_Profiles.Keys.CopyTo(ids, 0);
for (int i = 0; i < ids.Length; i++)
{
if (_Profiles[ids[i]].LoadProfile())
{
_Profiles[ids[i]].Avatar = _GetAvatar(_Profiles[ids[i]].AvatarFileName);
knownFiles.Add(Path.GetFileName(_Profiles[ids[i]].FileName));
}
else
_Profiles.Remove(ids[i]);
}
}
return 0;
List<string> files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.xml", true, true));
foreach (string file in files)
{
if (knownFiles.Contains(Path.GetFileName(file)))
continue;
CProfile profile = new CProfile
{
FileName = Path.Combine(CSettings.FolderProfiles, file)
};
if (profile.LoadProfile())
{
profile.Avatar = _GetAvatar(profile.AvatarFileName);
profile.ID = _ProfileIDs.Dequeue();
_Profiles.Add(profile.ID, profile);
}
}
_ProfilesChanged = true;
}
public static void DeleteProfile(int profileID)
private static void _LoadAvatars()
{
List<string> knownFiles = new List<string>();
if (_Avatars.Count > 0)
{
int[] ids = new int[_Avatars.Keys.Count];
_Avatars.Keys.CopyTo(ids, 0);
for (int i = 0; i < ids.Length; i++)
{
if (_Avatars[ids[i]].Reload())
knownFiles.Add(Path.GetFileName(_Avatars[ids[i]].FileName));
else
_Avatars.Remove(ids[i]);
}
}
List<string> files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.png", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpg", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.jpeg", true, true));
files.AddRange(CHelper.ListFiles(CSettings.FolderProfiles, "*.bmp", true, true));
foreach (string file in files)
{
if (knownFiles.Contains(Path.GetFileName(file)))
continue;
CAvatar avatar = new CAvatar(-1);
if (avatar.LoadFromFile(file))
{
avatar.ID = _AvatarIDs.Dequeue();
_Avatars.Add(avatar.ID, avatar);
}
}
_ProfilesChanged = true;
}
private static void _DeleteProfile(int profileID)
{
if (!ICProfileIDValid(profileID))
return;
if (_Profiles[profileID].FileName == "")
{
_RemoveProfile(profileID);
return;
}
try
{
//Check if profile saved in config
@@ -264,7 +637,8 @@ namespace Vocaluxe.Base
}
}
File.Delete(_Profiles[profileID].FileName);
_Profiles.RemoveAt(profileID);
_RemoveProfile(profileID);
//Check if profile is selected in game
for (int i = 0; i < CGame.Players.Length; i++)
{
@@ -278,11 +652,16 @@ namespace Vocaluxe.Base
{
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml");
}
_ProfilesChanged = true;
}
private static void _SortProfilesByName()
private static void _RemoveProfile(int profileID)
{
_Profiles.Sort(_CompareByPlayerName);
if (!ICProfileIDValid(profileID))
return;
_Profiles.Remove(profileID);
_ProfilesChanged = true;
}
private static int _CompareByPlayerName(CProfile a, CProfile b)
@@ -290,59 +669,17 @@ namespace Vocaluxe.Base
return String.CompareOrdinal(a.PlayerName, b.PlayerName);
}
#region private methods
private static CAvatar _GetAvatar(string fileName)
{
foreach (CAvatar avatar in _Avatars)
string Name = Path.GetFileName(fileName);
foreach (int id in _Avatars.Keys)
{
if (fileName == avatar.FileName)
return avatar;
if (Path.GetFileName(_Avatars[id].FileName) == Name)
return _Avatars[id];
}
return new CAvatar(-1);
}
private static void _SaveProfile(int profileID)
{
if (!ICProfileIDValid(profileID))
return;
if (_Profiles[profileID].FileName == "")
{
string filename = string.Empty;
foreach (char chr in _Profiles[profileID].PlayerName)
{
if (char.IsLetter(chr))
filename += chr.ToString();
}
if (filename == "")
filename = "1";
int i = 0;
while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + ".xml")))
{
i++;
if (!File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".xml")))
filename += i;
}
CProfile profile = _Profiles[profileID];
profile.FileName = Path.Combine(CSettings.FolderProfiles, filename + ".xml");
_Profiles[profileID] = profile;
}
_Profiles[profileID].SaveProfile();
}
private static void _LoadProfile(string fileName)
{
CProfile profile = new CProfile {FileName = Path.Combine(CSettings.FolderProfiles, fileName)};
if (profile.LoadProfile())
{
profile.Avatar = _GetAvatar(profile.AvatarFileName);
_Profiles.Add(profile);
}
}
#endregion private methods
}
}
+5
View File
@@ -91,5 +91,10 @@ namespace Vocaluxe.Base
{
return _Webcam.IsDeviceAvailable();
}
public static bool IsCapturing()
{
return _Webcam.IsCapturing();
}
}
}
+66 -19
View File
@@ -12,12 +12,14 @@ using ClientServerLib;
using Vocaluxe.Base;
using Vocaluxe.Lib.Input;
using VocaluxeLib;
using VocaluxeLib.Profile;
namespace Vocaluxe.Base.Server
{
static class CVocaluxeServer
{
private static CServer _Server;
private static CDiscover _Discover;
private static Dictionary<int, CClientHandler> _Clients;
public static CControllerFramework Controller = new CControllerFramework();
@@ -25,19 +27,24 @@ namespace Vocaluxe.Base.Server
public static void Init()
{
_Clients = new Dictionary<int, CClientHandler>();
_Server = new CServer(RequestHandler, CConfig.ServerPort);
_Server = new CServer(RequestHandler, CConfig.ServerPort, CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON);
_Discover = new CDiscover(CConfig.ServerPort, CCommands.ResponseKeyword);
Controller.Init();
}
public static void Start()
{
if (CConfig.Server == EOffOn.TR_CONFIG_ON)
if (CConfig.ServerActive == EOffOn.TR_CONFIG_ON)
{
_Server.Start();
_Discover.StartBroadcasting();
}
}
public static void Close()
{
_Server.Stop();
_Discover.Stop();
_Clients = new Dictionary<int, CClientHandler>();
}
@@ -148,32 +155,72 @@ namespace Vocaluxe.Base.Server
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)
if (_AddAvatar(avatarPictureJpg.data) != String.Empty)
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
break;
case CCommands.CommandSendProfile:
SProfile profile;
if (CCommands.DecodeCommandSendProfile(Message, out profile))
{
try
{
string AvatarFilename = _AddAvatar(profile.Avatar.data);
if (AvatarFilename != String.Empty)
{
CProfile p = new CProfile();
p.Active = EOffOn.TR_CONFIG_ON;
p.AvatarFileName = AvatarFilename;
p.Difficulty = (EGameDifficulty)profile.Difficulty;
p.GuestProfile = EOffOn.TR_CONFIG_OFF;
p.PlayerName = profile.PlayerName;
CProfiles.AddProfile(p);
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
}
catch (Exception)
{
}
}
break;
default:
break;
}
return answer;
}
private static string _AddAvatar(byte[] JpgData)
{
string result = String.Empty;
try
{
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
int i = 0;
while (File.Exists(filename + i + ".jpg"))
i++;
filename = filename + i + ".jpg";
FileStream fs = File.Create(filename);
fs.Write(JpgData, 0, JpgData.Length);
fs.Flush();
fs.Close();
CAvatar avatar = new CAvatar(-1);
if (avatar.LoadFromFile(filename))
{
CProfiles.AddAvatar(avatar);
result = filename;
}
}
catch { }
return result;
}
}
}
+5
View File
@@ -164,6 +164,11 @@ namespace Vocaluxe.Lib.Webcam
return _Devices.Count > 0;
}
public bool IsCapturing()
{
return _Webcam.IsRunning;
}
public bool Select(SWebcamConfig config)
{
//Close old camera connection
+1
View File
@@ -59,6 +59,7 @@ namespace Vocaluxe.Lib.Webcam
SWebcamConfig GetConfig();
SWebcamDevice[] GetDevices();
bool IsDeviceAvailable();
bool IsCapturing();
bool Select(SWebcamConfig webcamConfig);
}
+8
View File
@@ -197,15 +197,23 @@ namespace Vocaluxe
CController.Connect();
CLog.StopBenchmark(0, "Init Input");
Application.DoEvents();
// Init Game;
CLog.StartBenchmark(0, "Init Game");
CGame.Init();
CProfiles.Update();
CConfig.UsePlayers();
CLog.StopBenchmark(0, "Init Game");
Application.DoEvents();
// Init Party Modes;
CLog.StartBenchmark(0, "Init Party Modes");
CParty.Init();
CLog.StopBenchmark(0, "Init Party Modes");
Application.DoEvents();
}
catch (Exception e)
{
+93 -42
View File
@@ -23,6 +23,7 @@ using System.Windows.Forms;
using Vocaluxe.Base;
using VocaluxeLib;
using VocaluxeLib.Menu;
using VocaluxeLib.Profile;
namespace Vocaluxe.Screens
{
@@ -61,7 +62,10 @@ namespace Vocaluxe.Screens
private int _SelectingSwitchNr = -1;
private int _SelectingFastPlayerNr = 0;
private int _SelectedPlayerNr = -1;
private bool _AvatarsChanged = false;
private bool _ProfilesChanged = false;
#region public methods
public override void Init()
{
base.Init();
@@ -99,6 +103,9 @@ namespace Vocaluxe.Screens
_ChooseAvatarStatic = GetNewStatic();
_ChooseAvatarStatic.Visible = false;
_ChooseAvatarStatic.Aspect = EAspect.Crop;
CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged));
}
public override void LoadTheme(string xmlPath)
@@ -106,7 +113,10 @@ namespace Vocaluxe.Screens
base.LoadTheme(xmlPath);
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
{
_OriginalPlayerAvatarTextures[i] = _Statics[_StaticPlayerAvatar[i]].Texture;
_Statics[_StaticPlayerAvatar[i]].Aspect = EAspect.Crop;
}
for (int i = 1; i <= CSettings.MaxNumPlayer; i++)
_Equalizers["EqualizerPlayer" + i].ScreenHandles = true;
@@ -166,15 +176,19 @@ namespace Vocaluxe.Screens
//Check, if a player is selected
if (_NameSelections[_NameSelection].Selection > -1)
{
CProfile[] profiles = CProfiles.GetProfiles();
_SelectedPlayerNr = _NameSelections[_NameSelection].Selection;
if (profiles.Length <= _SelectedPlayerNr)
return true;
//Update Game-infos with new player
CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = _SelectedPlayerNr;
CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID;
//Update config for default players.
CConfig.Players[_SelectingFastPlayerNr - 1] = CProfiles.Profiles[_SelectedPlayerNr].FileName;
CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName;
CConfig.SaveConfig();
//Update texture and name
_Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName;
_Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName;
//Update profile-warning
_CheckPlayers();
//Update Tiles-List
@@ -418,10 +432,10 @@ namespace Vocaluxe.Screens
//Update Game-infos with new player
CGame.Players[_SelectingSwitchNr].ProfileID = CGame.Players[i].ProfileID;
//Update config for default players.
CConfig.Players[_SelectingSwitchNr] = CProfiles.Profiles[i].FileName;
CConfig.Players[_SelectingSwitchNr] = CProfiles.GetProfileFileName(CGame.Players[i].ProfileID);
//Update texture and name
_Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture;
_Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.Profiles[CGame.Players[i].ProfileID].PlayerName;
_Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID);
_Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID);
}
else if (_SelectingSwitchNr > -1)
{
@@ -433,14 +447,19 @@ namespace Vocaluxe.Screens
_Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = _OriginalPlayerAvatarTextures[_SelectingSwitchNr];
_Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr+1));
}
CProfile[] profiles = CProfiles.GetProfiles();
if (profiles.Length <= _SelectedPlayerNr)
return true;
//Update Game-infos with new player
CGame.Players[i].ProfileID = _SelectedPlayerNr;
CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID;
//Update config for default players.
CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].FileName;
CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName;
CConfig.SaveConfig();
//Update texture and name
_Statics[_StaticPlayerAvatar[i]].Texture = _ChooseAvatarStatic.Texture;
_Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName;
_Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName;
//Update profile-warning
_CheckPlayers();
//Update Tiles-List
@@ -457,6 +476,7 @@ namespace Vocaluxe.Screens
//Update texture and name
_Statics[_StaticPlayerAvatar[_SelectingSwitchNr]].Texture = _OriginalPlayerAvatarTextures[_SelectingSwitchNr];
_Texts[_TextPlayer[_SelectingSwitchNr]].Text = CProfiles.GetPlayerName(-1, (_SelectingSwitchNr + 1));
_NameSelections[_NameSelection].UpdateList();
}
}
_SelectingSwitchNr = -1;
@@ -473,14 +493,18 @@ namespace Vocaluxe.Screens
_SelectedPlayerNr = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent);
if (_SelectedPlayerNr != -1)
{
CProfile[] profiles = CProfiles.GetProfiles();
if (profiles.Length <= _SelectedPlayerNr)
return true;
//Update Game-infos with new player
CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = _SelectedPlayerNr;
CGame.Players[_SelectingFastPlayerNr - 1].ProfileID = profiles[_SelectedPlayerNr].ID;
//Update config for default players.
CConfig.Players[_SelectingFastPlayerNr - 1] = CProfiles.Profiles[_SelectedPlayerNr].FileName;
CConfig.Players[_SelectingFastPlayerNr - 1] = profiles[_SelectedPlayerNr].FileName;
CConfig.SaveConfig();
//Update texture and name
_Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName;
_Statics[_StaticPlayerAvatar[_SelectingFastPlayerNr - 1]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[_SelectingFastPlayerNr - 1]].Text = profiles[_SelectedPlayerNr].PlayerName;
//Update profile-warning
_CheckPlayers();
//Update Tiles-List
@@ -516,14 +540,18 @@ namespace Vocaluxe.Screens
{
if (CGame.Players[i].ProfileID == -1)
{
CProfile[] profiles = CProfiles.GetProfiles();
if (profiles.Length <= _SelectedPlayerNr)
return true;
//Update Game-infos with new player
CGame.Players[i].ProfileID = _SelectedPlayerNr;
CGame.Players[i].ProfileID = profiles[_SelectedPlayerNr].ID;
//Update config for default players.
CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].FileName;
CConfig.Players[i] = profiles[_SelectedPlayerNr].FileName;
CConfig.SaveConfig();
//Update texture and name
_Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName;
_Statics[_StaticPlayerAvatar[i]].Texture = profiles[_SelectedPlayerNr].Avatar.Texture;
_Texts[_TextPlayer[i]].Text = profiles[_SelectedPlayerNr].PlayerName;
//Update profile-warning
_CheckPlayers();
//Update Tiles-List
@@ -601,6 +629,9 @@ namespace Vocaluxe.Screens
public override bool UpdateGame()
{
if (_ProfilesChanged || _AvatarsChanged)
_LoadProfiles();
for (int i = 1; i <= CGame.NumPlayer; i++)
{
CSound.AnalyzeBuffer(i - 1);
@@ -615,30 +646,7 @@ namespace Vocaluxe.Screens
CSound.RecordStart();
_NameSelections[_NameSelection].Init();
_UpdateSlides();
_UpdatePlayerNumber();
_CheckMics();
_CheckPlayers();
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
{
_Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID) ?
CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture :
_OriginalPlayerAvatarTextures[i];
_Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1);
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
{
_SelectSlides[_SelectSlideDuetPlayer[i]].Clear();
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = i + 1 <= CGame.NumPlayer;
_SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart1);
_SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart2);
_SelectSlides[_SelectSlideDuetPlayer[i]].Selection = i % 2;
}
else
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false;
}
_LoadProfiles();
_SetInteractionToButton(_Buttons[_ButtonStart]);
}
@@ -658,6 +666,48 @@ namespace Vocaluxe.Screens
_Equalizers["EqualizerPlayer" + i].Draw();
return true;
}
#endregion public methods
#region private methods
private void _OnProfileChanged(EProfileChangedFlags Flags)
{
if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags))
_AvatarsChanged = true;
if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags))
_ProfilesChanged = true;
}
private void _LoadProfiles()
{
_NameSelections[_NameSelection].UpdateList();
_UpdateSlides();
_UpdatePlayerNumber();
_CheckMics();
_CheckPlayers();
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
{
_Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID) ?
CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID) :
_OriginalPlayerAvatarTextures[i];
_Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1);
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
{
_SelectSlides[_SelectSlideDuetPlayer[i]].Clear();
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = i + 1 <= CGame.NumPlayer;
_SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart1);
_SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart2);
_SelectSlides[_SelectSlideDuetPlayer[i]].Selection = i % 2;
}
else
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false;
}
_ProfilesChanged = false;
_AvatarsChanged = false;
}
private void _StartSong()
{
@@ -800,5 +850,6 @@ namespace Vocaluxe.Screens
_Texts[_TextWarningProfiles].Visible = false;
}
}
#endregion private methods
}
}
+161 -96
View File
@@ -18,6 +18,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
@@ -25,6 +26,7 @@ using System.Windows.Forms;
using Vocaluxe.Base;
using VocaluxeLib;
using VocaluxeLib.Menu;
using VocaluxeLib.Profile;
namespace Vocaluxe.Screens
{
@@ -58,6 +60,8 @@ namespace Vocaluxe.Screens
private const string _ButtonTakeSnapshot = "ButtonTakeSnapshot";
private const string _StaticAvatar = "StaticAvatar";
private bool _ProfilesChanged;
private bool _AvatarsChanged;
private EEditMode _EditMode;
@@ -74,6 +78,9 @@ namespace Vocaluxe.Screens
_ThemeStatics = new string[] {_StaticAvatar};
_EditMode = EEditMode.None;
_ProfilesChanged = false;
_AvatarsChanged = false;
CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged));
}
public override void LoadTheme(string xmlPath)
@@ -103,7 +110,8 @@ namespace Vocaluxe.Screens
break;
case EEditMode.PlayerName:
_SelectSlides[_SelectSlideProfiles].RenameValue(
CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection, keyEvent.Unicode));
CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, keyEvent.Unicode));
_ProfilesChanged = true;
break;
}
}
@@ -112,7 +120,10 @@ namespace Vocaluxe.Screens
switch (keyEvent.Key)
{
case Keys.Escape:
CGraphics.FadeTo(EScreens.ScreenMain);
if (_EditMode == EEditMode.PlayerName)
_EditMode = EEditMode.None;
else
CGraphics.FadeTo(EScreens.ScreenMain);
break;
case Keys.Enter:
@@ -145,7 +156,8 @@ namespace Vocaluxe.Screens
if (_EditMode == EEditMode.PlayerName)
{
_SelectSlides[_SelectSlideProfiles].RenameValue(
CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].Selection));
CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex));
_ProfilesChanged = true;
}
else
CGraphics.FadeTo(EScreens.ScreenMain);
@@ -157,22 +169,22 @@ namespace Vocaluxe.Screens
}
if (_SelectSlides[_SelectSlideDifficulty].Selected)
{
CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection);
}
else if (_SelectSlides[_SelectSlideAvatars].Selected)
{
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection,
_SelectSlides[_SelectSlideAvatars].Selection);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
_SelectSlides[_SelectSlideAvatars].ValueIndex);
}
else if (_SelectSlides[_SelectSlideGuestProfile].Selected)
{
CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection);
}
else if (_SelectSlides[_SelectSlideActive].Selected)
{
CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EOffOn)_SelectSlides[_SelectSlideActive].Selection);
}
}
@@ -204,24 +216,24 @@ namespace Vocaluxe.Screens
}
else if (_SelectSlides[_SelectSlideDifficulty].Selected)
{
CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection);
}
else if (_SelectSlides[_SelectSlideAvatars].Selected)
{
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection,
_SelectSlides[_SelectSlideAvatars].Selection);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
_SelectSlides[_SelectSlideAvatars].ValueIndex);
if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0)
_OnDiscardSnapshot();
}
else if (_SelectSlides[_SelectSlideGuestProfile].Selected)
{
CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection);
}
else if (_SelectSlides[_SelectSlideActive].Selected)
{
CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection,
CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex,
(EOffOn)_SelectSlides[_SelectSlideActive].Selection);
}
else if (_Buttons[_ButtonWebcam].Selected && CWebcam.IsDeviceAvailable())
@@ -239,6 +251,64 @@ namespace Vocaluxe.Screens
return true;
}
public override bool UpdateGame()
{
if (_AvatarsChanged)
_LoadAvatars(true);
if (_ProfilesChanged)
_LoadProfiles(true);
if (_SelectSlides[_SelectSlideProfiles].Selection > -1)
{
_Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
if (_EditMode == EEditMode.PlayerName)
_Buttons[_ButtonPlayerName].Text.Text += "|";
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].ValueIndex);
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].ValueIndex);
int avatarID = CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex);
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(avatarID);
if (CWebcam.IsDeviceAvailable() && CWebcam.IsCapturing())
{
if (_Snapshot == null)
CWebcam.GetFrame(ref _WebcamTexture);
_Statics[_StaticAvatar].Texture = _WebcamTexture;
}
else
_Statics[_StaticAvatar].Texture = CProfiles.GetAvatarTexture(avatarID);
}
return true;
}
public override void OnShow()
{
base.OnShow();
_LoadAvatars(false);
_LoadProfiles(false);
UpdateGame();
}
public override void OnClose()
{
base.OnClose();
_EditMode = EEditMode.None;
_OnDiscardSnapshot();
}
private void _OnProfileChanged(EProfileChangedFlags Flags)
{
if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags))
_AvatarsChanged = true;
if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags))
_ProfilesChanged = true;
}
private void _OnTakeSnapshot()
{
_Buttons[_ButtonSaveSnapshot].Visible = true;
@@ -261,30 +331,26 @@ namespace Vocaluxe.Screens
private void _OnSaveSnapshot()
{
const string filename = "snapshot";
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
int i = 0;
while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png")))
while (File.Exists(filename + i + ".png"))
i++;
_Snapshot.Save(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"), ImageFormat.Png);
CProfiles.LoadAvatars();
_LoadAvatars();
filename = filename + i + ".png";
_Snapshot.Save(filename, ImageFormat.Png);
_Snapshot = null;
CWebcam.Stop();
CDraw.RemoveTexture(ref _WebcamTexture);
for (int j = 0; j < CProfiles.Avatars.Length; j++)
{
if (CProfiles.Avatars[j].FileName == (filename + i + ".png"))
{
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, j);
break;
}
}
_Buttons[_ButtonSaveSnapshot].Visible = false;
_Buttons[_ButtonDiscardSnapshot].Visible = false;
_Buttons[_ButtonTakeSnapshot].Visible = false;
_Buttons[_ButtonWebcam].Visible = true;
int id = CProfiles.NewAvatar(filename);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, id);
_LoadAvatars(false);
}
private void _OnWebcam()
@@ -298,102 +364,101 @@ namespace Vocaluxe.Screens
_Buttons[_ButtonWebcam].Visible = false;
}
public override bool UpdateGame()
private void _NewProfile()
{
if (_SelectSlides[_SelectSlideProfiles].Selection > -1)
{
_Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection);
if (_EditMode == EEditMode.PlayerName)
_Buttons[_ButtonPlayerName].Text.Text += "|";
_EditMode = EEditMode.None;
int id = CProfiles.NewProfile();
_LoadProfiles(false);
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(id);
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex,
_SelectSlides[_SelectSlideAvatars].ValueIndex);
int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideAvatars].Selection = avatarNr;
if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0)
{
if (_Snapshot == null)
CWebcam.GetFrame(ref _WebcamTexture);
_Statics[_StaticAvatar].Texture = _WebcamTexture;
}
else
_Statics[_StaticAvatar].Texture = CProfiles.Avatars[avatarNr].Texture;
}
return true;
}
public override void OnShow()
{
base.OnShow();
CProfiles.LoadProfiles();
_LoadAvatars();
_LoadProfiles();
UpdateGame();
}
public override void OnClose()
{
base.OnClose();
_OnDiscardSnapshot();
_SetInteractionToButton(_Buttons[_ButtonPlayerName]);
_EditMode = EEditMode.PlayerName;
}
private void _SaveProfiles()
{
_EditMode = EEditMode.None;
CProfiles.SaveProfiles();
_LoadProfiles();
UpdateGame();
}
private void _DeleteProfile()
{
CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].Selection);
_LoadProfiles();
UpdateGame();
_EditMode = EEditMode.None;
CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].ValueIndex);
int selection = _SelectSlides[_SelectSlideProfiles].Selection;
if (_SelectSlides[_SelectSlideProfiles].NumValues - 1 > selection)
_SelectSlides[_SelectSlideProfiles].Selection = selection + 1;
else
_SelectSlides[_SelectSlideProfiles].Selection = selection - 1;
}
private void _LoadProfiles()
private void _LoadProfiles(bool Keep)
{
_EditMode = EEditMode.None;
string name = String.Empty;
if (_EditMode == EEditMode.PlayerName)
name = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex);
int selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex;
_SelectSlides[_SelectSlideProfiles].Clear();
for (int i = 0; i < CProfiles.NumProfiles; i++)
_SelectSlides[_SelectSlideProfiles].AddValue(CProfiles.GetPlayerName(i));
CProfile[] profiles = CProfiles.GetProfiles();
for (int i = 0; i < profiles.Length; i++)
_SelectSlides[_SelectSlideProfiles].AddValue(
profiles[i].PlayerName,
new STexture(-1),
profiles[i].ID,
-1);
if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0)
{
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideAvatars].Selection = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection);
if (selectedProfileID != -1)
_SelectSlides[_SelectSlideProfiles].SetSelectionByValueIndex(selectedProfileID);
else
{
_SelectSlides[_SelectSlideProfiles].Selection = 0;
selectedProfileID = _SelectSlides[_SelectSlideProfiles].ValueIndex;
}
if (!Keep)
{
_SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(selectedProfileID);
_SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(selectedProfileID);
_SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(selectedProfileID);
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(selectedProfileID));
}
if (_EditMode == EEditMode.PlayerName)
CProfiles.SetPlayerName(_SelectSlides[_SelectSlideProfiles].ValueIndex, name);
}
_ProfilesChanged = false;
}
private void _LoadAvatars()
private void _LoadAvatars(bool Keep)
{
int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex;
_SelectSlides[_SelectSlideAvatars].Clear();
for (int i = 0; i < CProfiles.NumAvatars; i++)
_SelectSlides[_SelectSlideAvatars].AddValue(CProfiles.Avatars[i].FileName);
}
CAvatar[] avatars = CProfiles.GetAvatars();
for (int i = 0; i < avatars.Length; i++)
_SelectSlides[_SelectSlideAvatars].AddValue(
Path.GetFileName(avatars[i].FileName),
new STexture(-1),
avatars[i].ID,
-1);
private void _NewProfile()
{
_EditMode = EEditMode.None;
CProfiles.NewProfile();
_LoadProfiles();
_SelectSlides[_SelectSlideProfiles].LastValue();
if (Keep)
{
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(selectedAvatarID);
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].ValueIndex, selectedAvatarID);
}
else
_SelectSlides[_SelectSlideAvatars].SetSelectionByValueIndex(CProfiles.GetAvatarID(_SelectSlides[_SelectSlideProfiles].ValueIndex));
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection,
_SelectSlides[_SelectSlideAvatars].Selection);
_SetInteractionToButton(_Buttons[_ButtonPlayerName]);
_EditMode = EEditMode.PlayerName;
}
_AvatarsChanged = false;
}
}
}
+1 -1
View File
@@ -334,7 +334,7 @@ namespace Vocaluxe.Screens
_Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H;
}
if (CProfiles.ICProfileIDValid(players[p].ProfileID))
_Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[players[p].ProfileID].Avatar.Texture;
_Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.GetAvatarTextureFromProfile(players[p].ProfileID);
}
if (CConfig.ScoreAnimationTime < 1)
+2 -2
View File
@@ -1398,7 +1398,7 @@ namespace Vocaluxe.Screens
for (int i = 0; i < CGame.NumPlayer; i++)
{
if (CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID))
_Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture;
_Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.GetAvatarTextureFromProfile(CGame.Players[i].ProfileID);
else
_Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Visible = false;
}
@@ -1409,7 +1409,7 @@ namespace Vocaluxe.Screens
for (int i = 0; i < CGame.NumPlayer; i++)
{
if (CProfiles.ICProfileIDValid(CGame.Players[i].ProfileID))
_Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.Profiles[CGame.Players[i].ProfileID].PlayerName;
_Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID);
else
_Texts[_TextNames[i, CGame.NumPlayer - 1]].Visible = false;
}
+2
View File
@@ -70,6 +70,8 @@ namespace VocaluxeLib
float GetDefaultMedleyFadeOutTime();
int GetMedleyMinSeriesLength();
float GetMedleyMinDuration();
string GetFolderProfiles();
}
public interface ITheme
+8 -3
View File
@@ -22,6 +22,8 @@ using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;
using VocaluxeLib.Profile;
namespace VocaluxeLib.Menu
{
struct SThemeNameSelection
@@ -487,6 +489,7 @@ namespace VocaluxeLib.Menu
{
SRectF rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z);
CStatic tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect);
tileStatic.Aspect = EAspect.Crop;
CText tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.NameSpace, rect.Z, _Theme.NameHeight, rect.W, EAlignment.Center, _Theme.NameStyle,
_Theme.NameFont, _Theme.NameColor, "");
_Tiles.Add(new CTile(tileStatic, tileText, -1));
@@ -497,16 +500,18 @@ namespace VocaluxeLib.Menu
private void _UpdateVisibleProfiles()
{
_VisibleProfiles.Clear();
for (int i = 0; i < CBase.Profiles.GetProfiles().Length; i++)
CProfile[] profiles = CBase.Profiles.GetProfiles();
for (int i = 0; i < profiles.Length; i++)
{
bool visible = CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON;
bool visible = profiles[i].Active == EOffOn.TR_CONFIG_ON;
if (visible)
{
//Show profile only if active
for (int p = 0; p < CBase.Game.GetNumPlayer(); p++)
{
//Don't show profile if is selected, but if selected and guest
if (CBase.Game.GetPlayers()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile == EOffOn.TR_CONFIG_OFF)
if (CBase.Game.GetPlayers()[p].ProfileID == profiles[i].ID && profiles[i].GuestProfile == EOffOn.TR_CONFIG_OFF)
visible = false;
}
}
+14 -11
View File
@@ -9,34 +9,37 @@ namespace VocaluxeLib.Profile
{
public class CAvatar
{
private int _ID;
public int ID
{
get { return _ID; }
}
public int ID;
public string FileName;
public STexture Texture;
public CAvatar(int ID)
{
_ID = ID;
this.ID = ID;
FileName = String.Empty;
Texture = new STexture(-1);
}
public void LoadFromFile(string NewFileName)
public bool LoadFromFile(string NewFileName)
{
FileName = NewFileName;
CBase.Drawing.RemoveTexture(ref Texture);
Texture = CBase.Drawing.AddTexture(FileName);
return (Texture.Index != -1);
}
public void Reload()
public bool Reload()
{
STexture oldTexture = Texture;
Texture = CBase.Drawing.AddTexture(FileName);
CBase.Drawing.RemoveTexture(ref oldTexture);
return Texture.Index != -1;
}
public void Unload()
{
CBase.Drawing.RemoveTexture(ref Texture);
Texture = CBase.Drawing.AddTexture(FileName);
}
}
}
+37 -10
View File
@@ -16,20 +16,24 @@ namespace VocaluxeLib.Profile
ConformanceLevel = ConformanceLevel.Document
};
private int _ID;
private int _AvatarID;
public int ID
{
get { return _ID; }
}
public int ID;
public string PlayerName;
public string FileName;
public string AvatarFileName;
public EGameDifficulty Difficulty;
public CAvatar Avatar; //should be removed! use avatar id
private CAvatar _Avatar;
public CAvatar Avatar
{
get { return _Avatar; }
set
{
_Avatar = value;
AvatarFileName = _Avatar.FileName;
}
}
public EOffOn GuestProfile;
public EOffOn Active;
@@ -78,6 +82,29 @@ namespace VocaluxeLib.Profile
public void SaveProfile()
{
if (FileName == String.Empty)
{
string filename = string.Empty;
foreach (char chr in PlayerName)
{
if (char.IsLetter(chr))
filename += chr.ToString();
}
if (filename == "")
filename = "1";
int i = 0;
while (File.Exists(Path.Combine(CBase.Settings.GetFolderProfiles(), filename + ".xml")))
{
i++;
if (!File.Exists(Path.Combine(CBase.Settings.GetFolderProfiles(), filename + i + ".xml")))
filename += i;
}
FileName = Path.Combine(Environment.CurrentDirectory, CBase.Settings.GetFolderProfiles(), filename + ".xml");
}
if (FileName == String.Empty)
return;
@@ -99,7 +126,7 @@ namespace VocaluxeLib.Profile
writer.WriteStartElement("Info");
writer.WriteElementString("PlayerName", PlayerName);
writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), Difficulty));
writer.WriteElementString("Avatar", Avatar.FileName);
writer.WriteElementString("Avatar", Path.GetFileName(Avatar.FileName));
writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), GuestProfile));
writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), Active));
writer.WriteEndElement();