Merge branch 'develop' of github.com:Flamefire/Vocaluxe into sound-player

Conflicts:
	VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs
This commit is contained in:
Florian Küpper committed 2014-08-09 20:04:41 +02:00
commit 8722844646
48 files changed
+399 -521

No files matched your search

-226
View File
@@ -5,230 +5,4 @@
<Folder>Blue</Folder> <Folder>Blue</Folder>
<Author>flokuep</Author> <Author>flokuep</Author>
</Info> </Info>
<Cover>
<Cover1>
<Name>NoCover</Name>
<Path>NoCover.png</Path>
</Cover1>
<Cover2>
<Name>A</Name>
<Path>A.png</Path>
</Cover2>
<Cover3>
<Name>B</Name>
<Path>B.png</Path>
</Cover3>
<Cover4>
<Name>C</Name>
<Path>C.png</Path>
</Cover4>
<Cover5>
<Name>D</Name>
<Path>D.png</Path>
</Cover5>
<Cover6>
<Name>E</Name>
<Path>E.png</Path>
</Cover6>
<Cover7>
<Name>F</Name>
<Path>F.png</Path>
</Cover7>
<Cover8>
<Name>G</Name>
<Path>G.png</Path>
</Cover8>
<Cover9>
<Name>H</Name>
<Path>H.png</Path>
</Cover9>
<Cover10>
<Name>I</Name>
<Path>I.png</Path>
</Cover10>
<Cover11>
<Name>J</Name>
<Path>J.png</Path>
</Cover11>
<Cover12>
<Name>K</Name>
<Path>K.png</Path>
</Cover12>
<Cover13>
<Name>L</Name>
<Path>L.png</Path>
</Cover13>
<Cover14>
<Name>M</Name>
<Path>M.png</Path>
</Cover14>
<Cover15>
<Name>N</Name>
<Path>N.png</Path>
</Cover15>
<Cover16>
<Name>O</Name>
<Path>O.png</Path>
</Cover16>
<Cover17>
<Name>P</Name>
<Path>P.png</Path>
</Cover17>
<Cover18>
<Name>Q</Name>
<Path>Q.png</Path>
</Cover18>
<Cover19>
<Name>R</Name>
<Path>R.png</Path>
</Cover19>
<Cover20>
<Name>S</Name>
<Path>S.png</Path>
</Cover20>
<Cover21>
<Name>T</Name>
<Path>T.png</Path>
</Cover21>
<Cover22>
<Name>U</Name>
<Path>U.png</Path>
</Cover22>
<Cover23>
<Name>V</Name>
<Path>V.png</Path>
</Cover23>
<Cover24>
<Name>W</Name>
<Path>W.png</Path>
</Cover24>
<Cover25>
<Name>X</Name>
<Path>X.png</Path>
</Cover25>
<Cover26>
<Name>Y</Name>
<Path>Y.png</Path>
</Cover26>
<Cover27>
<Name>Z</Name>
<Path>Z.png</Path>
</Cover27>
<Cover28>
<Name>#</Name>
<Path>#.png</Path>
</Cover28>
<Cover29>
<Name>No Year</Name>
<Path>NoYear.png</Path>
</Cover29>
<Cover30>
<Name>Ohne Jahr</Name>
<Path>OhneJahr.png</Path>
</Cover30>
<Cover31>
<Name>1900 - 1909</Name>
<Path>1900er.png</Path>
</Cover31>
<Cover32>
<Name>1910 - 1919</Name>
<Path>1910er.png</Path>
</Cover32>
<Cover33>
<Name>1920 - 1929</Name>
<Path>20er.png</Path>
</Cover33>
<Cover34>
<Name>1930 - 1939</Name>
<Path>30er.png</Path>
</Cover34>
<Cover35>
<Name>1940 - 1949</Name>
<Path>40er.png</Path>
</Cover35>
<Cover36>
<Name>1950 - 1959</Name>
<Path>50er.png</Path>
</Cover36>
<Cover37>
<Name>1960 - 1969</Name>
<Path>60er.png</Path>
</Cover37>
<Cover38>
<Name>1970 - 1979</Name>
<Path>70er.png</Path>
</Cover38>
<Cover39>
<Name>1980 - 1989</Name>
<Path>80er.png</Path>
</Cover39>
<Cover40>
<Name>1990 - 1999</Name>
<Path>90er.png</Path>
</Cover40>
<Cover41>
<Name>2000 - 2009</Name>
<Path>2000er.png</Path>
</Cover41>
<Cover42>
<Name>2010 - 2019</Name>
<Path>2010er.png</Path>
</Cover42>
<Cover43>
<Name>No Language</Name>
<Path>NoLanguage.png</Path>
</Cover43>
<Cover44>
<Name>Ohne Sprache</Name>
<Path>OhneSprache.png</Path>
</Cover44>
<Cover45>
<Name>German</Name>
<Path>German.png</Path>
</Cover45>
<Cover46>
<Name>English</Name>
<Path>English.png</Path>
</Cover46>
<Cover47>
<Name>French</Name>
<Path>French.png</Path>
</Cover47>
<Cover48>
<Name>Italian</Name>
<Path>Italian.png</Path>
</Cover48>
<Cover49>
<Name>Spanish</Name>
<Path>Spanish.png</Path>
</Cover49>
<Cover50>
<Name>Polish</Name>
<Path>Polish.png</Path>
</Cover50>
<Cover51>
<Name>No Edition</Name>
<Path>NoEdition.png</Path>
</Cover51>
<Cover52>
<Name>Ohne Edition</Name>
<Path>OhneEdition.png</Path>
</Cover52>
<Cover53>
<Name>No Genre</Name>
<Path>NoGenre.png</Path>
</Cover53>
<Cover54>
<Name>Ohne Genre</Name>
<Path>OhneGenre.png</Path>
</Cover54>
<Cover55>
<Name>All Songs</Name>
<Path>AllSongs.png</Path>
</Cover55>
<Cover56>
<Name>Alle Songs</Name>
<Path>AlleSongs.png</Path>
</Cover56>
</Cover>
</root> </root>
File renamed without changes.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 260 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 258 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 260 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 256 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 259 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 259 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 258 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 259 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 254 KiB

After

Width:  |  Height:  |  Size: 254 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 275 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 268 KiB

After

Width:  |  Height:  |  Size: 268 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 264 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 267 KiB

After

Width:  |  Height:  |  Size: 267 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 275 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 270 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 273 KiB

After

Width:  |  Height:  |  Size: 273 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 275 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 274 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 273 KiB

After

Width:  |  Height:  |  Size: 273 KiB

+10 -3
View File
@@ -16,7 +16,9 @@
#endregion #endregion
using System; using System;
#if WIN
using System.Diagnostics; using System.Diagnostics;
#endif
using System.ServiceModel; using System.ServiceModel;
using System.ServiceModel.Web; using System.ServiceModel.Web;
using System.Net; using System.Net;
@@ -160,7 +162,7 @@ namespace ServerLib
catch (CommunicationException) catch (CommunicationException)
{ {
_Host.Abort(); _Host.Abort();
MessageBox.Show("Problem while initialization of webserver. You may use a different port (Change in config.xml)"); MessageBox.Show("Problem while initialization of webserver. You may try a different port (Change it in config.xml)");
} }
} }
else else
@@ -188,7 +190,7 @@ namespace ServerLib
{ {
FileName = "VocaluxeServerConfig.exe", FileName = "VocaluxeServerConfig.exe",
WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
Arguments = port + " " + (_Encrypted ? "true" : "false") + (reserve ? " reserve" : ""), Arguments = AppDomain.CurrentDomain.FriendlyName + " " + port + " " + (_Encrypted ? "true" : "false") + (reserve ? " true" : ""),
UseShellExecute = true, UseShellExecute = true,
CreateNoWindow = true, CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
@@ -198,10 +200,15 @@ namespace ServerLib
using (Process p = Process.Start(info)) using (Process p = Process.Start(info))
{ {
p.WaitForExit(); p.WaitForExit();
if (p.ExitCode != 0)
MessageBox.Show("Registering the Server failed (Code " + p.ExitCode + ")!\r\nThe Server might not work correctly.");
p.Close(); p.Close();
} }
} }
catch (Exception) {} catch (Exception e)
{
MessageBox.Show("Registering the Server failed (" + e + ")!\r\nThe Server might not work correctly.");
}
#else #else
//Required? //Required?
+1 -1
View File
@@ -188,7 +188,7 @@ namespace Vocaluxe.Base
if (xmlReader != null) if (xmlReader != null)
{ {
_Covers.Clear(); _Covers.Clear();
List<string> cover = xmlReader.GetValues("Cover"); List<string> cover = xmlReader.GetNames("//root/Cover/*");
foreach (string coverName in cover) foreach (string coverName in cover)
{ {
string name; string name;
+1 -2
View File
@@ -353,8 +353,7 @@ namespace Vocaluxe.Base
if (!eventsAvailable) if (!eventsAvailable)
keyEvent = inputKeyEvent; keyEvent = inputKeyEvent;
if (keyEvent.Key == Keys.Left || keyEvent.Key == Keys.Right || keyEvent.Key == Keys.Up || keyEvent.Key == Keys.Down || keyEvent.Key == Keys.NumPad0 || if (keyEvent.IsArrowKey() || keyEvent.Key == Keys.NumPad0 || keyEvent.Key == Keys.D0)
keyEvent.Key == Keys.D0)
{ {
_Cursor.Deactivate(); _Cursor.Deactivate();
+1 -1
View File
@@ -168,7 +168,7 @@ namespace Vocaluxe.Base
private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts) private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts)
{ {
texts = new Dictionary<string, string>(); texts = new Dictionary<string, string>();
IEnumerable<string> names = xmlReader.GetAttributes("resources", "name"); IEnumerable<string> names = xmlReader.GetAttributes("//resources/string", "name");
foreach (string name in names) foreach (string name in names)
{ {
string value; string value;
+1 -1
View File
@@ -246,10 +246,10 @@ namespace Vocaluxe.Base
loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author"); loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author");
loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder"); loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder");
loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile"); loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile");
loaded &= xmlReader.GetInnerValues("PartyScreens", ref pm.ScreenFiles);
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor);
loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor);
loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience");
loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles);
if (!loaded) if (!loaded)
{ {
+1 -1
View File
@@ -71,7 +71,7 @@ namespace Vocaluxe.Base
{ {
if (songPointer.SortString != "") if (songPointer.SortString != "")
{ {
if (lastCategory == null || songPointer.SortString != lastCategory.Name) if (lastCategory == null || String.Compare(songPointer.SortString, lastCategory.Name, StringComparison.CurrentCultureIgnoreCase) != 0)
{ {
lastCategory = new CCategory(songPointer.SortString); lastCategory = new CCategory(songPointer.SortString);
_Categories.Add(lastCategory); _Categories.Add(lastCategory);
+1 -1
View File
@@ -155,7 +155,7 @@ namespace Vocaluxe.Base
list.Add(new CSongPointer(song.ID, value)); list.Add(new CSongPointer(song.ID, value));
else else
{ {
if (list.Count == 0) if (values.Count == 0)
list.Add(new CSongPointer(song.ID, "")); list.Add(new CSongPointer(song.ID, ""));
else else
list.AddRange(values.Select(val => new CSongPointer(song.ID, val))); list.AddRange(values.Select(val => new CSongPointer(song.ID, val)));
+3 -3
View File
@@ -485,12 +485,12 @@ namespace Vocaluxe.Base
skin.PartyModeID = theme.PartyModeID; skin.PartyModeID = theme.PartyModeID;
skin.SkinList = new Dictionary<string, CSkinElement>(); skin.SkinList = new Dictionary<string, CSkinElement>();
List<string> names = xmlReader.GetValues("Skins"); List<string> names = xmlReader.GetNames("//root/Skins/*");
foreach (string str in names) foreach (string str in names)
skin.SkinList[str] = new CSkinElement(); skin.SkinList[str] = new CSkinElement();
skin.VideoList = new Dictionary<string, CVideoSkinElement>(); skin.VideoList = new Dictionary<string, CVideoSkinElement>();
names = xmlReader.GetValues("Videos"); names = xmlReader.GetNames("//root/Videos/*");
foreach (string str in names) foreach (string str in names)
skin.VideoList[str] = new CVideoSkinElement(); skin.VideoList[str] = new CVideoSkinElement();
_Skins.Add(skin); _Skins.Add(skin);
@@ -665,7 +665,7 @@ namespace Vocaluxe.Base
} }
var colorScheme = new List<SColorScheme>(); var colorScheme = new List<SColorScheme>();
List<string> names = xmlReader.GetValues("ColorSchemes"); List<string> names = xmlReader.GetNames("//root/ColorSchemes/*");
foreach (string str in names) foreach (string str in names)
{ {
var scheme = new SColorScheme {Name = str}; var scheme = new SColorScheme {Name = str};
-92
View File
@@ -15,8 +15,6 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System.Diagnostics;
using System.Drawing;
using Vocaluxe.Lib.Video; using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -115,94 +113,4 @@ namespace Vocaluxe.Base
#endregion VideoDecoder #endregion VideoDecoder
} }
class CVideoPlayer
{
private CTexture _VideoTexture;
private int _VideoStream;
private readonly Stopwatch _VideoTimer = new Stopwatch();
private bool _Finished;
private bool _Loaded;
public bool IsFinished
{
get { return _Finished || !_Loaded; }
}
public bool Loop
{
set { CVideo.SetLoop(_VideoStream, value); }
}
public void Load(string videoName)
{
_VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1));
_Loaded = true;
CVideo.Pause(_VideoStream);
}
public void Start()
{
_VideoTimer.Reset();
_Finished = false;
//CVideo.VdSkip(_VideoStream, 0f, 0f);
_VideoTimer.Start();
CVideo.Resume(_VideoStream);
}
public void Pause()
{
CVideo.Pause(_VideoStream);
_VideoTimer.Stop();
}
public void Resume()
{
CVideo.Resume(_VideoStream);
_VideoTimer.Start();
}
public void Draw()
{
if (!_Finished)
{
float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f;
_Finished = CVideo.Finished(_VideoStream);
CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime);
}
if (_VideoTexture == null)
return;
var bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH);
RectangleF rect;
CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop);
CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4));
}
public void PreLoad()
{
bool paused = _VideoTimer.IsRunning;
if (paused)
CVideo.Resume(_VideoStream);
float videoTime = 0f;
while (_VideoTexture == null && videoTime < 1f)
{
float dummy;
CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy);
videoTime += 0.05f;
}
if (paused)
CVideo.Pause(_VideoStream);
}
public void Close()
{
CVideo.Close(_VideoStream);
CDraw.RemoveTexture(ref _VideoTexture);
_Loaded = false;
_Finished = false;
_VideoTimer.Reset();
}
}
} }
+97
View File
@@ -0,0 +1,97 @@
using System.Diagnostics;
using System.Drawing;
using VocaluxeLib;
using VocaluxeLib.Draw;
namespace Vocaluxe.Base
{
class CVideoPlayer
{
private CTexture _VideoTexture;
private int _VideoStream;
private readonly Stopwatch _VideoTimer = new Stopwatch();
private bool _Finished;
private bool _Loaded;
public bool IsFinished
{
get { return _Finished || !_Loaded; }
}
public bool Loop
{
set { CVideo.SetLoop(_VideoStream, value); }
}
public void Load(string videoName)
{
_VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1));
_Loaded = true;
CVideo.Pause(_VideoStream);
}
public void Start()
{
_VideoTimer.Reset();
_Finished = false;
//CVideo.VdSkip(_VideoStream, 0f, 0f);
_VideoTimer.Start();
CVideo.Resume(_VideoStream);
}
public void Pause()
{
CVideo.Pause(_VideoStream);
_VideoTimer.Stop();
}
public void Resume()
{
CVideo.Resume(_VideoStream);
_VideoTimer.Start();
}
public void Draw()
{
if (!_Finished)
{
float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f;
_Finished = CVideo.Finished(_VideoStream);
CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime);
}
if (_VideoTexture == null)
return;
var bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH);
RectangleF rect;
CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop);
CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4));
}
public void PreLoad()
{
bool paused = _VideoTimer.IsRunning;
if (paused)
CVideo.Resume(_VideoStream);
float videoTime = 0f;
while (_VideoTexture == null && videoTime < 1f)
{
float dummy;
CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy);
videoTime += 0.05f;
}
if (paused)
CVideo.Pause(_VideoStream);
}
public void Close()
{
CVideo.Close(_VideoStream);
CDraw.RemoveTexture(ref _VideoTexture);
_Loaded = false;
_Finished = false;
_VideoTimer.Reset();
}
}
}
+1 -1
View File
@@ -122,7 +122,7 @@ namespace Vocaluxe.Lib.Playlist
Songs = new List<CPlaylistSong>(); Songs = new List<CPlaylistSong>();
List<string> songs = xmlReader.GetValues("Songs"); List<string> songs = xmlReader.GetNames("//root/Songs/*");
foreach (string songEntry in songs) foreach (string songEntry in songs)
{ {
+14 -1
View File
@@ -15,6 +15,7 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System.Windows.Forms;
using Vocaluxe.Base; using Vocaluxe.Base;
using Vocaluxe.Base.Server; using Vocaluxe.Base.Server;
using VocaluxeLib; using VocaluxeLib;
@@ -75,7 +76,7 @@ namespace Vocaluxe.Screens
public override bool HandleMouse(SMouseEvent mouseEvent) public override bool HandleMouse(SMouseEvent mouseEvent)
{ {
if (mouseEvent.LB) if (mouseEvent.LB || mouseEvent.RB)
{ {
CGraphics.HidePopup(EPopupScreens.PopupServerQR); CGraphics.HidePopup(EPopupScreens.PopupServerQR);
return true; return true;
@@ -83,6 +84,18 @@ namespace Vocaluxe.Screens
return false; return false;
} }
public override bool HandleInput(SKeyEvent keyEvent)
{
switch (keyEvent.Key)
{
case Keys.Escape:
case Keys.Back:
CGraphics.HidePopup(EPopupScreens.PopupServerQR);
return true;
}
return base.HandleInput(keyEvent);
}
public override bool UpdateGame() public override bool UpdateGame()
{ {
return true; return true;
+1 -1
View File
@@ -284,7 +284,7 @@ namespace Vocaluxe.Screens
else else
{ {
_Pos += num; _Pos += num;
_Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1); _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1, true);
} }
} }
-4
View File
@@ -399,12 +399,8 @@ namespace Vocaluxe.Screens
private void _ChangeRound(int num) private void _ChangeRound(int num)
{ {
if (_Points.NumRounds < 1)
return;
_Round += num; _Round += num;
_Round = _Round.Clamp(-1, _Points.NumRounds - 1); _Round = _Round.Clamp(-1, _Points.NumRounds - 1);
if (_Round >= _Points.NumRounds)
_Round = _Points.NumRounds - 1;
_UpdateRatings(); _UpdateRatings();
} }
+1
View File
@@ -219,6 +219,7 @@
<Compile Include="Base\CPlaylistElement.cs" /> <Compile Include="Base\CPlaylistElement.cs" />
<Compile Include="Base\CPreviewPlayer.cs" /> <Compile Include="Base\CPreviewPlayer.cs" />
<Compile Include="Base\CRecord.cs" /> <Compile Include="Base\CRecord.cs" />
<Compile Include="Base\CVideoPlayer.cs" />
<Compile Include="COSFunctions.cs" /> <Compile Include="COSFunctions.cs" />
<Compile Include="Lib\Database\CCoverDB.cs" /> <Compile Include="Lib\Database\CCoverDB.cs" />
<Compile Include="Lib\Database\CDatabaseBase.cs" /> <Compile Include="Lib\Database\CDatabaseBase.cs" />
+34 -29
View File
@@ -17,6 +17,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@@ -63,8 +64,18 @@ namespace VocaluxeLib
return (int)result; return (int)result;
} }
/// <summary>
/// Makes sure val is between min and max
/// Asserts that min&lt;=max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T> public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{ {
Debug.Assert(min.CompareTo(max) <= 0);
if (val.CompareTo(min) < 0) if (val.CompareTo(min) < 0)
return min; return min;
if (val.CompareTo(max) > 0) if (val.CompareTo(max) > 0)
@@ -72,6 +83,27 @@ namespace VocaluxeLib
return val; return val;
} }
/// <summary>
/// Makes sure val is between min and max but also handles the case where min&gt;max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="preferMin"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max, bool preferMin) where T : IComparable<T>
{
if (min.CompareTo(max) > 0)
{
if (preferMin)
max = min;
else
min = max;
}
return Clamp(val, min, max);
}
/// <summary> /// <summary>
/// Concat strings into one string with ", " as separator. /// Concat strings into one string with ", " as separator.
/// </summary> /// </summary>
@@ -88,32 +120,6 @@ namespace VocaluxeLib
return result; return result;
} }
public static int TryReadInt(StreamReader sr)
{
string value = String.Empty;
try
{
int tmp = sr.Peek();
//Check for ' ', ?, ?, \n, \r, E
while (tmp != 32 && tmp != 19 && tmp != 16 && tmp != 13 && tmp != 10 && tmp != 69)
{
if (sr.EndOfStream)
break;
var chr = (char)sr.Read();
value += chr.ToString();
tmp = sr.Peek();
}
}
catch (Exception)
{
return 0;
}
int result;
return Int32.TryParse(value, out result) ? result : 0;
}
public static void SetRect(SRectF bounds, out SRectF rect, float rectAspect, EAspect aspect) public static void SetRect(SRectF bounds, out SRectF rect, float rectAspect, EAspect aspect)
{ {
var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H);
@@ -279,13 +285,12 @@ namespace VocaluxeLib
/// </summary> /// </summary>
/// <param name="path">Path in which the file should be stored</param> /// <param name="path">Path in which the file should be stored</param>
/// <param name="filename">filename (including extension)</param> /// <param name="filename">filename (including extension)</param>
/// <param name="withPath">Whether the fullpath or only the filename should be returned</param>
/// <returns></returns> /// <returns></returns>
public static string GetUniqueFileName(string path, string filename, bool withPath = true) public static string GetUniqueFileName(string path, string filename, bool withPath = true)
{ {
string ext = Path.GetExtension(filename); string ext = Path.GetExtension(filename);
filename = Path.GetFileNameWithoutExtension(filename); filename = Path.GetFileNameWithoutExtension(filename) ?? "1";
if (filename == null)
filename = "1";
if (File.Exists(Path.Combine(path, filename + ext))) if (File.Exists(Path.Combine(path, filename + ext)))
{ {
int i = 1; int i = 1;
+43 -80
View File
@@ -57,49 +57,44 @@ namespace VocaluxeLib
} }
} }
public bool TryGetEnumValue<T>(string cast, ref T value) public bool TryGetEnumValue<T>(string xPath, ref T value)
where T : struct where T : struct
{ {
string val; string val;
if (GetValue(cast, out val, Enum.GetName(typeof(T), value))) if (GetValue(xPath, out val, Enum.GetName(typeof(T), value)))
return CHelper.TryParse(val, out value, true); return CHelper.TryParse(val, out value, true);
return false; return false;
} }
public bool TryGetIntValue(string cast, ref int value) public bool TryGetIntValue(string xPath, ref int value)
{ {
string val; string val;
if (GetValue(cast, out val, value.ToString())) if (GetValue(xPath, out val, value.ToString()))
return int.TryParse(val, out value); return int.TryParse(val, out value);
return false; return false;
} }
public bool TryGetIntValueRange(string cast, ref int value, int min = 0, int max = 100) public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100)
{ {
bool result = TryGetIntValue(cast, ref value); bool result = TryGetIntValue(xPath, ref value);
if (result) if (result)
{ value = value.Clamp(min, max);
if (value < min)
value = min;
else if (value > max)
value = max;
}
return result; return result;
} }
public bool TryGetFloatValue(string cast, ref float value) public bool TryGetFloatValue(string xPath, ref float value)
{ {
string val; string val;
return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value); return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
} }
public bool GetValue(string cast, out string value, string defaultValue) public bool GetValue(string xPath, out string value, string defaultValue)
{ {
int resultCt = 0; int resultCt = 0;
string val = string.Empty; string val = string.Empty;
_Navigator.MoveToFirstChild(); _Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(cast); XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext()) while (iterator.MoveNext())
{ {
@@ -116,77 +111,45 @@ namespace VocaluxeLib
return true; return true;
} }
public List<string> GetValues(string cast) public List<string> GetNames(string xPath)
{ {
var values = new List<string>(); var values = new List<string>();
_Navigator.MoveToRoot(); _Navigator.MoveToRoot();
_Navigator.MoveToFirstChild(); XPathNodeIterator iterator = _Navigator.Select(xPath);
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.LocalName);
while (_Navigator.MoveToNext())
values.Add(_Navigator.LocalName);
return values;
}
public IEnumerable<string> GetAttributes(string cast, string attribute)
{
var values = new List<string>();
_Navigator.MoveToRoot();
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.LocalName);
while (_Navigator.MoveToNext())
values.Add(_Navigator.GetAttribute(attribute, ""));
return values;
}
public bool GetInnerValues(string cast, ref List<string> values)
{
_Navigator.MoveToRoot();
_Navigator.MoveToFirstChild();
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.Value);
while (_Navigator.MoveToNext())
values.Add(_Navigator.Value);
return true;
}
public bool ItemExists(string cast)
{
int results = 0;
_Navigator.MoveToFirstChild();
XPathNodeIterator iterator = _Navigator.Select(cast);
while (iterator.MoveNext()) while (iterator.MoveNext())
results++; values.Add(iterator.Current.LocalName);
if (results == 0) return values;
return false; }
public IEnumerable<string> GetAttributes(string xPath, string attribute)
{
var values = new List<string>();
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
values.Add(iterator.Current.GetAttribute(attribute, ""));
return values;
}
public bool GetValues(string xPath, ref List<string> values)
{
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
values.Add(iterator.Current.Value);
return true; return true;
} }
public bool ItemExists(string xPath)
{
_Navigator.MoveToRoot();
return _Navigator.Select(xPath).MoveNext();
}
} }
} }
@@ -442,6 +442,7 @@ namespace VocaluxeLib.Menu.SongMenu
_SelectionNr = categoryNr; _SelectionNr = categoryNr;
else else
_SelectionNr = -1; _SelectionNr = -1;
_PreviewNr = _SelectionNr;
} }
public virtual void UnloadTextures() {} public virtual void UnloadTextures() {}
@@ -519,6 +520,11 @@ namespace VocaluxeLib.Menu.SongMenu
protected void _ResetPreview() protected void _ResetPreview()
{ {
CBase.PreviewPlayer.Stop(); CBase.PreviewPlayer.Stop();
//Make sure we don't have a preview here otherwise a change won't be recognized
//(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown
//Use internal nr because this function gets called from withing setPreviewNr
_PreviewNrInternal = -1;
} }
#region ThemeEdit #region ThemeEdit
+20 -20
View File
@@ -57,8 +57,8 @@ namespace VocaluxeLib.Menu.SongMenu
private int _Offset; private int _Offset;
private float _Length = -1f; private float _Length = -1f;
private int _LastKnownNumSongs; private int _LastKnownElements;
private int _LastKnownCategory = -1; private int _LastKnownCategory;
private bool _MouseWasInRect; private bool _MouseWasInRect;
@@ -72,7 +72,7 @@ namespace VocaluxeLib.Menu.SongMenu
set set
{ {
int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
base._SelectionNr = value.Clamp(-1, max - 1); base._SelectionNr = value.Clamp(-1, max - 1, true);
//Update list in case we scrolled //Update list in case we scrolled
_UpdateList(); _UpdateList();
@@ -267,17 +267,18 @@ namespace VocaluxeLib.Menu.SongMenu
public override void OnShow() public override void OnShow()
{ {
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory()) _LastKnownElements = -1; //Force refresh of list
_EnterCategory(0); if (!CBase.Songs.IsInCategory())
else
{ {
if (CBase.Songs.IsInCategory()) if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1)
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); _EnterCategory(0);
else
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
} }
if (CBase.Songs.IsInCategory())
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr);
else
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
_PreviewNr = _SelectionNr; _PreviewNr = _SelectionNr;
_AfterCategoryChange(); _UpdateListIfRequired();
} }
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
@@ -503,18 +504,16 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
base._EnterCategory(categoryNr); base._EnterCategory(categoryNr);
_PreviewNr = 0;
SetSelectedSong(0); SetSelectedSong(0);
_AfterCategoryChange(); _UpdateListIfRequired();
} }
protected override void _LeaveCategory() protected override void _LeaveCategory()
{ {
base._LeaveCategory(); base._LeaveCategory();
_PreviewNr = 0;
SetSelectedCategory(0); SetSelectedCategory(0);
_AfterCategoryChange(); _UpdateListIfRequired();
} }
private void _NextCategory() private void _NextCategory()
@@ -535,20 +534,21 @@ namespace VocaluxeLib.Menu.SongMenu
} }
} }
private void _AfterCategoryChange() private void _UpdateListIfRequired()
{ {
if ((_LastKnownNumSongs == CBase.Songs.GetNumSongsVisible()) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())) int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if ((_LastKnownElements == curElements) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex()))
return; return;
_LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex(); _LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex();
_LastKnownNumSongs = CBase.Songs.GetNumSongsVisible(); _LastKnownElements = curElements;
CBase.Songs.UpdateRandomSongList(); CBase.Songs.UpdateRandomSongList();
_UpdateList(true); _UpdateList(true);
} }
private int _GetOffsetForPosition(int index, int rowNum = 0) private int _GetOffsetForPosition(int index, int rowNum = 0)
{ {
return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1)); return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1, true));
} }
private void _UpdateList(bool force = false) private void _UpdateList(bool force = false)
@@ -568,7 +568,7 @@ namespace VocaluxeLib.Menu.SongMenu
bool isInCategory = CBase.Songs.IsInCategory(); bool isInCategory = CBase.Songs.IsInCategory();
int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1)); offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1), true);
if (offset == _Offset && !force) if (offset == _Offset && !force)
return; return;
+22 -1
View File
@@ -240,7 +240,7 @@ namespace VocaluxeLib.Songs
break; break;
case "LANGUAGE": case "LANGUAGE":
if (value.Length > 1) if (value.Length > 1)
_Song.Languages.Add(value); _Song.Languages.Add(_UnifyLanguage(value));
else else
_LogWarning("Invalid language"); _LogWarning("Invalid language");
break; break;
@@ -449,6 +449,27 @@ namespace VocaluxeLib.Songs
return true; return true;
} }
private static string _UnifyLanguage(string lang)
{
if (lang != "")
{
lang = Char.ToUpperInvariant(lang[0]) + lang.Substring(1).ToLowerInvariant();
switch (lang)
{
case "Englisch":
lang = "English";
break;
case "Deutsch":
lang = "German";
break;
case "Spanisch":
lang = "Spanish";
break;
}
}
return lang;
}
private enum ENoteReadMode private enum ENoteReadMode
{ {
Normal, Normal,
+3 -2
View File
@@ -60,9 +60,10 @@ namespace WebserverInitalConfig
HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)"); HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)");
} }
public void ReserveUrl() public void ReserveUrl(bool secure)
{ {
_ReserveUrl("https://+:" + _Port + "/"); string http = secure ? "https" : "http";
_ReserveUrl(http + "://+:" + _Port + "/");
} }
private void _BindCert(X509Certificate cert) private void _BindCert(X509Certificate cert)
+115 -39
View File
@@ -25,6 +25,7 @@ using System.Security.Cryptography.X509Certificates;
namespace WebserverInitalConfig namespace WebserverInitalConfig
{ {
// ReSharper disable InconsistentNaming
static class HttpApi static class HttpApi
{ {
private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0); private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0);
@@ -144,6 +145,14 @@ namespace WebserverInitalConfig
public HTTP_SERVICE_CONFIG_URLACL_PARAM ParamDesc; public HTTP_SERVICE_CONFIG_URLACL_PARAM ParamDesc;
} }
[StructLayout(LayoutKind.Sequential)]
private struct HTTP_SERVICE_CONFIG_URLACL_QUERY
{
public HTTP_SERVICE_CONFIG_QUERY_TYPE QueryDesc;
public HTTP_SERVICE_CONFIG_URLACL_KEY KeyDesc;
public uint dwToken;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct HTTP_SERVICE_CONFIG_URLACL_KEY public struct HTTP_SERVICE_CONFIG_URLACL_KEY
{ {
@@ -227,7 +236,7 @@ namespace WebserverInitalConfig
if (retVal == ERROR_FILE_NOT_FOUND) if (retVal == ERROR_FILE_NOT_FOUND)
return; return;
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 if (ERROR_INSUFFICIENT_BUFFER == retVal)
{ {
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
@@ -431,7 +440,7 @@ namespace WebserverInitalConfig
IntPtr.Zero); IntPtr.Zero);
if (ERROR_NO_MORE_ITEMS == retVal) if (ERROR_NO_MORE_ITEMS == retVal)
break; break;
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 if (ERROR_INSUFFICIENT_BUFFER == retVal)
{ {
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
@@ -485,6 +494,101 @@ namespace WebserverInitalConfig
return result.ToArray(); return result.ToArray();
} }
private static HTTP_SERVICE_CONFIG_URLACL_SET QueryReservation(string networkURL)
{
if (String.IsNullOrEmpty(networkURL))
throw new ArgumentNullException("networkURL");
HTTP_SERVICE_CONFIG_URLACL_SET res = new HTTP_SERVICE_CONFIG_URLACL_SET();
res.KeyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY("");
CallHttpApi(
delegate
{
HTTP_SERVICE_CONFIG_URLACL_QUERY inputquery = new HTTP_SERVICE_CONFIG_URLACL_QUERY
{
QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryExact,
KeyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL)
};
IntPtr pInputQuery = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY)));
Marshal.StructureToPtr(inputquery, pInputQuery, false);
IntPtr pOutputConfigInfo = IntPtr.Zero;
int returnLength = 0;
try
{
uint retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
pInputQuery,
Marshal.SizeOf(inputquery),
pOutputConfigInfo,
returnLength,
out returnLength,
IntPtr.Zero);
if (ERROR_INSUFFICIENT_BUFFER == retVal)
{
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
pInputQuery,
Marshal.SizeOf(inputquery),
pOutputConfigInfo,
returnLength,
out returnLength,
IntPtr.Zero);
if (ERROR_FILE_NOT_FOUND == retVal)
return;
ThrowWin32ExceptionIfError(retVal);
res = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET));
}
else if (ERROR_FILE_NOT_FOUND == retVal)
return;
else
ThrowWin32ExceptionIfError(retVal);
}
finally
{
Marshal.FreeCoTaskMem(pInputQuery);
if (pOutputConfigInfo != IntPtr.Zero)
Marshal.FreeCoTaskMem(pOutputConfigInfo);
}
}
);
return res;
}
public static uint DeleteReservation(string networkURL)
{
uint retVal = NOERROR;
if (String.IsNullOrEmpty(networkURL))
throw new ArgumentNullException("networkURL");
HTTP_SERVICE_CONFIG_URLACL_SET oldReservation = QueryReservation(networkURL);
if (oldReservation.KeyDesc.pUrlPrefix == "" && networkURL.Contains("+"))
{
networkURL = networkURL.Replace('+', '*');
oldReservation = QueryReservation(networkURL);
}
if (oldReservation.KeyDesc.pUrlPrefix == "")
return ERROR_FILE_NOT_FOUND;
CallHttpApi(
delegate
{
IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
Marshal.StructureToPtr(oldReservation, pInputConfigInfo, false);
try
{
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
pInputConfigInfo,
Marshal.SizeOf(oldReservation),
IntPtr.Zero);
}
finally
{
Marshal.FreeCoTaskMem(pInputConfigInfo);
}
});
return retVal;
}
public static void ReserveURL(string networkURL, string securityDescriptor) public static void ReserveURL(string networkURL, string securityDescriptor)
{ {
if (String.IsNullOrEmpty(networkURL)) if (String.IsNullOrEmpty(networkURL))
@@ -495,7 +599,7 @@ namespace WebserverInitalConfig
CallHttpApi( CallHttpApi(
delegate delegate
{ {
uint retVal = (uint)NOERROR; // NOERROR = 0 uint retVal;
HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL); HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL);
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
@@ -514,13 +618,15 @@ namespace WebserverInitalConfig
Marshal.SizeOf(inputConfigInfoSet), Marshal.SizeOf(inputConfigInfoSet),
IntPtr.Zero); IntPtr.Zero);
if (ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183 if (ERROR_ALREADY_EXISTS == retVal)
{ {
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, retVal = DeleteReservation(networkURL);
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, if (ERROR_FILE_NOT_FOUND == retVal)
pInputConfigInfo, {
Marshal.SizeOf(inputConfigInfoSet), string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") :
IntPtr.Zero); networkURL.Replace("http", "https");
retVal = DeleteReservation(networkURLOld);
}
if (NOERROR == retVal) if (NOERROR == retVal)
{ {
@@ -530,41 +636,11 @@ namespace WebserverInitalConfig
Marshal.SizeOf(inputConfigInfoSet), Marshal.SizeOf(inputConfigInfoSet),
IntPtr.Zero); IntPtr.Zero);
} }
else if (ERROR_FILE_NOT_FOUND == retVal) // ERROR_FILE_NOT_FOUND = 2
{
string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") :
networkURL.Replace("http", "https");
HTTP_SERVICE_CONFIG_URLACL_KEY keyDescOld = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURLOld);
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDescOld = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSetOld = new HTTP_SERVICE_CONFIG_URLACL_SET();
inputConfigInfoSetOld.KeyDesc = keyDescOld;
inputConfigInfoSetOld.ParamDesc = paramDescOld;
IntPtr pInputConfigInfoOld = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
Marshal.StructureToPtr(inputConfigInfoSetOld, pInputConfigInfoOld, false);
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
pInputConfigInfoOld,
Marshal.SizeOf(inputConfigInfoSetOld),
IntPtr.Zero);
if (NOERROR == retVal)
{
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
pInputConfigInfo,
Marshal.SizeOf(inputConfigInfoSet),
IntPtr.Zero);
}
}
} }
} }
finally finally
{ {
Marshal.FreeCoTaskMem(pInputConfigInfo); Marshal.FreeCoTaskMem(pInputConfigInfo);
HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
} }
if (NOERROR != retVal) if (NOERROR != retVal)
ThrowWin32ExceptionIfError(retVal); ThrowWin32ExceptionIfError(retVal);
+23 -12
View File
@@ -30,25 +30,29 @@ namespace WebserverInitalConfig
private static void Main(string[] args) private static void Main(string[] args)
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
{ {
int result = 0;
try try
{ {
int port; int port;
if (args.Length < 2 || !int.TryParse(args[0], out port)) if (args.Length < 3 || !int.TryParse(args[1], out port))
{ {
Console.WriteLine("Usage: VocaluxeServerConfig port isHttps"); Console.WriteLine("Usage: VocaluxeServerConfig exeName port isHttps [reserve]");
Environment.Exit(-1); result = -1;
} }
else else
{ {
CConfigHttpApi config = new CConfigHttpApi("Vocaluxe", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Vocaluxe.exe"), "0.0.0.0", port, true); String exeName = args[0];
bool isSecure = (args[2].ToLower() == "true");
bool doReserve = (args.Length >= 4 && args[3].ToLower() == "true");
CConfigHttpApi config = new CConfigHttpApi(exeName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exeName), "0.0.0.0", port, true);
try try
{ {
config.AddFirewallRule(); config.AddFirewallRule();
if (args[1].ToLower() == "true") if (isSecure)
config.CreateAndAddCert(Dns.GetHostName()); config.CreateAndAddCert(Dns.GetHostName());
if ((args.Length >= 3 && args[2] == "reserve") || CConfigHttpApi.IsAdministrator()) if (doReserve || CConfigHttpApi.IsAdministrator())
config.ReserveUrl(); config.ReserveUrl(isSecure);
} }
catch (AuthenticationException) catch (AuthenticationException)
{ {
@@ -56,8 +60,8 @@ namespace WebserverInitalConfig
{ {
UseShellExecute = true, UseShellExecute = true,
WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
FileName = Process.GetCurrentProcess().MainModule.FileName, FileName = AppDomain.CurrentDomain.FriendlyName,
Arguments = args[0] + " " + args[1], Arguments = String.Join(" ", args),
Verb = "runas", Verb = "runas",
CreateNoWindow = true, CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
@@ -65,21 +69,28 @@ namespace WebserverInitalConfig
try try
{ {
Process.Start(proc); using (Process p = Process.Start(proc))
{
p.WaitForExit();
result = p.ExitCode;
p.Close();
}
} }
catch catch
{ {
// The user refused the elevation. // The user refused the elevation.
// Do nothing and return directly ... // Do nothing and return directly ...
Environment.Exit(-1); result = -3;
} }
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
MessageBox.Show("Error while installing server: " + e.Message); MessageBox.Show("Error while installing server: " + e.Message + "\r\n\r\nIn " + e.TargetSite + "\r\nBacktrace: " + e.StackTrace);
result = -4;
} }
Environment.Exit(result);
} }
} }
} }