diff --git a/Output/Cover/Blue.xml b/Output/Cover/Blue.xml index bfa423a7..9befe7d3 100644 --- a/Output/Cover/Blue.xml +++ b/Output/Cover/Blue.xml @@ -5,230 +5,4 @@ Blue flokuep - - - NoCover - NoCover.png - - - A - A.png - - - B - B.png - - - C - C.png - - - D - D.png - - - E - E.png - - - F - F.png - - - G - G.png - - - H - H.png - - - I - I.png - - - J - J.png - - - K - K.png - - - L - L.png - - - M - M.png - - - N - N.png - - - O - O.png - - - P - P.png - - - Q - Q.png - - - R - R.png - - - S - S.png - - - T - T.png - - - U - U.png - - - V - V.png - - - W - W.png - - - X - X.png - - - Y - Y.png - - - Z - Z.png - - - # - #.png - - - No Year - NoYear.png - - - Ohne Jahr - OhneJahr.png - - - 1900 - 1909 - 1900er.png - - - 1910 - 1919 - 1910er.png - - - 1920 - 1929 - 20er.png - - - 1930 - 1939 - 30er.png - - - 1940 - 1949 - 40er.png - - - 1950 - 1959 - 50er.png - - - 1960 - 1969 - 60er.png - - - 1970 - 1979 - 70er.png - - - 1980 - 1989 - 80er.png - - - 1990 - 1999 - 90er.png - - - 2000 - 2009 - 2000er.png - - - 2010 - 2019 - 2010er.png - - - No Language - NoLanguage.png - - - Ohne Sprache - OhneSprache.png - - - German - German.png - - - English - English.png - - - French - French.png - - - Italian - Italian.png - - - Spanish - Spanish.png - - - Polish - Polish.png - - - No Edition - NoEdition.png - - - Ohne Edition - OhneEdition.png - - - No Genre - NoGenre.png - - - Ohne Genre - OhneGenre.png - - - All Songs - AllSongs.png - - - Alle Songs - AlleSongs.png - - diff --git a/Output/Cover/Blue/1900er.png b/Output/Cover/Blue/1900 - 1909.png similarity index 100% rename from Output/Cover/Blue/1900er.png rename to Output/Cover/Blue/1900 - 1909.png diff --git a/Output/Cover/Blue/1910er.png b/Output/Cover/Blue/1910 - 1919.png similarity index 100% rename from Output/Cover/Blue/1910er.png rename to Output/Cover/Blue/1910 - 1919.png diff --git a/Output/Cover/Blue/20er.png b/Output/Cover/Blue/1920 - 1929.png similarity index 100% rename from Output/Cover/Blue/20er.png rename to Output/Cover/Blue/1920 - 1929.png diff --git a/Output/Cover/Blue/30er.png b/Output/Cover/Blue/1930 - 1939.png similarity index 100% rename from Output/Cover/Blue/30er.png rename to Output/Cover/Blue/1930 - 1939.png diff --git a/Output/Cover/Blue/40er.png b/Output/Cover/Blue/1940 - 1949.png similarity index 100% rename from Output/Cover/Blue/40er.png rename to Output/Cover/Blue/1940 - 1949.png diff --git a/Output/Cover/Blue/50er.png b/Output/Cover/Blue/1950 - 1959.png similarity index 100% rename from Output/Cover/Blue/50er.png rename to Output/Cover/Blue/1950 - 1959.png diff --git a/Output/Cover/Blue/60er.png b/Output/Cover/Blue/1960 - 1969.png similarity index 100% rename from Output/Cover/Blue/60er.png rename to Output/Cover/Blue/1960 - 1969.png diff --git a/Output/Cover/Blue/70er.png b/Output/Cover/Blue/1970 - 1979.png similarity index 100% rename from Output/Cover/Blue/70er.png rename to Output/Cover/Blue/1970 - 1979.png diff --git a/Output/Cover/Blue/80er.png b/Output/Cover/Blue/1980 - 1989.png similarity index 100% rename from Output/Cover/Blue/80er.png rename to Output/Cover/Blue/1980 - 1989.png diff --git a/Output/Cover/Blue/90er.png b/Output/Cover/Blue/1990 - 1999.png similarity index 100% rename from Output/Cover/Blue/90er.png rename to Output/Cover/Blue/1990 - 1999.png diff --git a/Output/Cover/Blue/2000er.png b/Output/Cover/Blue/2000 - 2009.png similarity index 100% rename from Output/Cover/Blue/2000er.png rename to Output/Cover/Blue/2000 - 2009.png diff --git a/Output/Cover/Blue/2010er.png b/Output/Cover/Blue/2010 - 2019.png similarity index 100% rename from Output/Cover/Blue/2010er.png rename to Output/Cover/Blue/2010 - 2019.png diff --git a/Output/Cover/Blue/AllSongs.png b/Output/Cover/Blue/All Songs.png similarity index 100% rename from Output/Cover/Blue/AllSongs.png rename to Output/Cover/Blue/All Songs.png diff --git a/Output/Cover/Blue/AlleSongs.png b/Output/Cover/Blue/Alle Songs.png similarity index 100% rename from Output/Cover/Blue/AlleSongs.png rename to Output/Cover/Blue/Alle Songs.png diff --git a/Output/Cover/Blue/EmptyCover.png b/Output/Cover/Blue/EmptyCover.png new file mode 100644 index 00000000..048a8dc0 Binary files /dev/null and b/Output/Cover/Blue/EmptyCover.png differ diff --git a/Output/Cover/Blue/NoCover.png b/Output/Cover/Blue/No Cover.png similarity index 100% rename from Output/Cover/Blue/NoCover.png rename to Output/Cover/Blue/No Cover.png diff --git a/Output/Cover/Blue/NoEdition.png b/Output/Cover/Blue/No Edition.png similarity index 100% rename from Output/Cover/Blue/NoEdition.png rename to Output/Cover/Blue/No Edition.png diff --git a/Output/Cover/Blue/NoGenre.png b/Output/Cover/Blue/No Genre.png similarity index 100% rename from Output/Cover/Blue/NoGenre.png rename to Output/Cover/Blue/No Genre.png diff --git a/Output/Cover/Blue/NoLanguage.png b/Output/Cover/Blue/No Language.png similarity index 100% rename from Output/Cover/Blue/NoLanguage.png rename to Output/Cover/Blue/No Language.png diff --git a/Output/Cover/Blue/NoYear.png b/Output/Cover/Blue/No Year.png similarity index 100% rename from Output/Cover/Blue/NoYear.png rename to Output/Cover/Blue/No Year.png diff --git a/Output/Cover/Blue/OhneEdition.png b/Output/Cover/Blue/Ohne Edition.png similarity index 100% rename from Output/Cover/Blue/OhneEdition.png rename to Output/Cover/Blue/Ohne Edition.png diff --git a/Output/Cover/Blue/OhneGenre.png b/Output/Cover/Blue/Ohne Genre.png similarity index 100% rename from Output/Cover/Blue/OhneGenre.png rename to Output/Cover/Blue/Ohne Genre.png diff --git a/Output/Cover/Blue/OhneJahr.png b/Output/Cover/Blue/Ohne Jahr.png similarity index 100% rename from Output/Cover/Blue/OhneJahr.png rename to Output/Cover/Blue/Ohne Jahr.png diff --git a/Output/Cover/Blue/OhneSprache.png b/Output/Cover/Blue/Ohne Sprache.png similarity index 100% rename from Output/Cover/Blue/OhneSprache.png rename to Output/Cover/Blue/Ohne Sprache.png diff --git a/ServerLib/CServer.cs b/ServerLib/CServer.cs index d0162e74..e4c46301 100644 --- a/ServerLib/CServer.cs +++ b/ServerLib/CServer.cs @@ -16,7 +16,9 @@ #endregion using System; +#if WIN using System.Diagnostics; +#endif using System.ServiceModel; using System.ServiceModel.Web; using System.Net; @@ -160,7 +162,7 @@ namespace ServerLib catch (CommunicationException) { _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 @@ -188,7 +190,7 @@ namespace ServerLib { FileName = "VocaluxeServerConfig.exe", WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, - Arguments = port + " " + (_Encrypted ? "true" : "false") + (reserve ? " reserve" : ""), + Arguments = AppDomain.CurrentDomain.FriendlyName + " " + port + " " + (_Encrypted ? "true" : "false") + (reserve ? " true" : ""), UseShellExecute = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, @@ -198,10 +200,15 @@ namespace ServerLib using (Process p = Process.Start(info)) { p.WaitForExit(); + if (p.ExitCode != 0) + MessageBox.Show("Registering the Server failed (Code " + p.ExitCode + ")!\r\nThe Server might not work correctly."); p.Close(); } } - catch (Exception) {} + catch (Exception e) + { + MessageBox.Show("Registering the Server failed (" + e + ")!\r\nThe Server might not work correctly."); + } #else //Required? diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 62527cd3..ac9cc10c 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -188,7 +188,7 @@ namespace Vocaluxe.Base if (xmlReader != null) { _Covers.Clear(); - List cover = xmlReader.GetValues("Cover"); + List cover = xmlReader.GetNames("//root/Cover/*"); foreach (string coverName in cover) { string name; diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index cef1f480..6526ac02 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -353,8 +353,7 @@ namespace Vocaluxe.Base if (!eventsAvailable) keyEvent = inputKeyEvent; - if (keyEvent.Key == Keys.Left || keyEvent.Key == Keys.Right || keyEvent.Key == Keys.Up || keyEvent.Key == Keys.Down || keyEvent.Key == Keys.NumPad0 || - keyEvent.Key == Keys.D0) + if (keyEvent.IsArrowKey() || keyEvent.Key == Keys.NumPad0 || keyEvent.Key == Keys.D0) { _Cursor.Deactivate(); diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index c78b3ed5..a86faf0f 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -168,7 +168,7 @@ namespace Vocaluxe.Base private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary texts) { texts = new Dictionary(); - IEnumerable names = xmlReader.GetAttributes("resources", "name"); + IEnumerable names = xmlReader.GetAttributes("//resources/string", "name"); foreach (string name in names) { string value; diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 1dada7f9..22bc3b33 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -246,10 +246,10 @@ namespace Vocaluxe.Base 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/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/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); + loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles); if (!loaded) { diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index 282e62a7..4c16bf3a 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -71,7 +71,7 @@ namespace Vocaluxe.Base { 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); _Categories.Add(lastCategory); diff --git a/Vocaluxe/Base/CSongSorter.cs b/Vocaluxe/Base/CSongSorter.cs index f1703224..f521118f 100644 --- a/Vocaluxe/Base/CSongSorter.cs +++ b/Vocaluxe/Base/CSongSorter.cs @@ -155,7 +155,7 @@ namespace Vocaluxe.Base list.Add(new CSongPointer(song.ID, value)); else { - if (list.Count == 0) + if (values.Count == 0) list.Add(new CSongPointer(song.ID, "")); else list.AddRange(values.Select(val => new CSongPointer(song.ID, val))); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index e382191e..520353a4 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -485,12 +485,12 @@ namespace Vocaluxe.Base skin.PartyModeID = theme.PartyModeID; skin.SkinList = new Dictionary(); - List names = xmlReader.GetValues("Skins"); + List names = xmlReader.GetNames("//root/Skins/*"); foreach (string str in names) skin.SkinList[str] = new CSkinElement(); skin.VideoList = new Dictionary(); - names = xmlReader.GetValues("Videos"); + names = xmlReader.GetNames("//root/Videos/*"); foreach (string str in names) skin.VideoList[str] = new CVideoSkinElement(); _Skins.Add(skin); @@ -665,7 +665,7 @@ namespace Vocaluxe.Base } var colorScheme = new List(); - List names = xmlReader.GetValues("ColorSchemes"); + List names = xmlReader.GetNames("//root/ColorSchemes/*"); foreach (string str in names) { var scheme = new SColorScheme {Name = str}; diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 5bb596e9..3d57cbd3 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -15,8 +15,6 @@ // along with Vocaluxe. If not, see . #endregion -using System.Diagnostics; -using System.Drawing; using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; @@ -115,94 +113,4 @@ namespace Vocaluxe.Base #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(); - } - } } \ No newline at end of file diff --git a/Vocaluxe/Base/CVideoPlayer.cs b/Vocaluxe/Base/CVideoPlayer.cs new file mode 100644 index 00000000..8dd47d4b --- /dev/null +++ b/Vocaluxe/Base/CVideoPlayer.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index bdadd99b..ff86215f 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -122,7 +122,7 @@ namespace Vocaluxe.Lib.Playlist Songs = new List(); - List songs = xmlReader.GetValues("Songs"); + List songs = xmlReader.GetNames("//root/Songs/*"); foreach (string songEntry in songs) { diff --git a/Vocaluxe/Screens/CPopupScreenServerQR.cs b/Vocaluxe/Screens/CPopupScreenServerQR.cs index a961edd9..febb08a2 100644 --- a/Vocaluxe/Screens/CPopupScreenServerQR.cs +++ b/Vocaluxe/Screens/CPopupScreenServerQR.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Server; using VocaluxeLib; @@ -75,7 +76,7 @@ namespace Vocaluxe.Screens public override bool HandleMouse(SMouseEvent mouseEvent) { - if (mouseEvent.LB) + if (mouseEvent.LB || mouseEvent.RB) { CGraphics.HidePopup(EPopupScreens.PopupServerQR); return true; @@ -83,6 +84,18 @@ namespace Vocaluxe.Screens 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() { return true; diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index 01848911..010a3cce 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -284,7 +284,7 @@ namespace Vocaluxe.Screens else { _Pos += num; - _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1); + _Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1, true); } } diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 1b1c133f..19ec84ef 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -399,12 +399,8 @@ namespace Vocaluxe.Screens private void _ChangeRound(int num) { - if (_Points.NumRounds < 1) - return; _Round += num; _Round = _Round.Clamp(-1, _Points.NumRounds - 1); - if (_Round >= _Points.NumRounds) - _Round = _Points.NumRounds - 1; _UpdateRatings(); } diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 41753b7a..ca4e0c7b 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -219,6 +219,7 @@ + diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index 2edec3ce..411d39ec 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; @@ -63,8 +64,18 @@ namespace VocaluxeLib return (int)result; } + /// + /// Makes sure val is between min and max + /// Asserts that min<=max + /// + /// + /// + /// + /// + /// Clamped value public static T Clamp(this T val, T min, T max) where T : IComparable { + Debug.Assert(min.CompareTo(max) <= 0); if (val.CompareTo(min) < 0) return min; if (val.CompareTo(max) > 0) @@ -72,6 +83,27 @@ namespace VocaluxeLib return val; } + /// + /// Makes sure val is between min and max but also handles the case where min>max + /// + /// + /// + /// + /// + /// + /// Clamped value + public static T Clamp(this T val, T min, T max, bool preferMin) where T : IComparable + { + if (min.CompareTo(max) > 0) + { + if (preferMin) + max = min; + else + min = max; + } + return Clamp(val, min, max); + } + /// /// Concat strings into one string with ", " as separator. /// @@ -88,32 +120,6 @@ namespace VocaluxeLib 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) { var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); @@ -279,13 +285,12 @@ namespace VocaluxeLib /// /// Path in which the file should be stored /// filename (including extension) + /// Whether the fullpath or only the filename should be returned /// public static string GetUniqueFileName(string path, string filename, bool withPath = true) { string ext = Path.GetExtension(filename); - filename = Path.GetFileNameWithoutExtension(filename); - if (filename == null) - filename = "1"; + filename = Path.GetFileNameWithoutExtension(filename) ?? "1"; if (File.Exists(Path.Combine(path, filename + ext))) { int i = 1; diff --git a/VocaluxeLib/CXMLReader.cs b/VocaluxeLib/CXMLReader.cs index c35f12ef..1603af81 100644 --- a/VocaluxeLib/CXMLReader.cs +++ b/VocaluxeLib/CXMLReader.cs @@ -57,49 +57,44 @@ namespace VocaluxeLib } } - public bool TryGetEnumValue(string cast, ref T value) + public bool TryGetEnumValue(string xPath, ref T value) where T : struct { 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 false; } - public bool TryGetIntValue(string cast, ref int value) + public bool TryGetIntValue(string xPath, ref int value) { string val; - if (GetValue(cast, out val, value.ToString())) + if (GetValue(xPath, out val, value.ToString())) return int.TryParse(val, out value); 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 (value < min) - value = min; - else if (value > max) - value = max; - } + value = value.Clamp(min, max); return result; } - public bool TryGetFloatValue(string cast, ref float value) + public bool TryGetFloatValue(string xPath, ref float value) { 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; string val = string.Empty; - _Navigator.MoveToFirstChild(); - XPathNodeIterator iterator = _Navigator.Select(cast); + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) { @@ -116,77 +111,45 @@ namespace VocaluxeLib return true; } - public List GetValues(string cast) + public List GetNames(string xPath) { var values = new List(); _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - _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 GetAttributes(string cast, string attribute) - { - var values = new List(); - - _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 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); - + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) - results++; + values.Add(iterator.Current.LocalName); - if (results == 0) - return false; + return values; + } + + public IEnumerable GetAttributes(string xPath, string attribute) + { + var values = new List(); + + _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 values) + { + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + while (iterator.MoveNext()) + values.Add(iterator.Current.Value); return true; } + + public bool ItemExists(string xPath) + { + _Navigator.MoveToRoot(); + + return _Navigator.Select(xPath).MoveNext(); + } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 82974e48..06dbdda1 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -442,6 +442,7 @@ namespace VocaluxeLib.Menu.SongMenu _SelectionNr = categoryNr; else _SelectionNr = -1; + _PreviewNr = _SelectionNr; } public virtual void UnloadTextures() {} @@ -519,6 +520,11 @@ namespace VocaluxeLib.Menu.SongMenu protected void _ResetPreview() { 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 diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 68e142e2..f58d337f 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -57,8 +57,8 @@ namespace VocaluxeLib.Menu.SongMenu private int _Offset; private float _Length = -1f; - private int _LastKnownNumSongs; - private int _LastKnownCategory = -1; + private int _LastKnownElements; + private int _LastKnownCategory; private bool _MouseWasInRect; @@ -72,7 +72,7 @@ namespace VocaluxeLib.Menu.SongMenu set { 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 _UpdateList(); @@ -267,17 +267,18 @@ namespace VocaluxeLib.Menu.SongMenu public override void OnShow() { - if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory()) - _EnterCategory(0); - else + _LastKnownElements = -1; //Force refresh of list + if (!CBase.Songs.IsInCategory()) { - if (CBase.Songs.IsInCategory()) - SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); - else - SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr); + if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1) + _EnterCategory(0); } + if (CBase.Songs.IsInCategory()) + SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr); + else + SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr); _PreviewNr = _SelectionNr; - _AfterCategoryChange(); + _UpdateListIfRequired(); } public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options) @@ -503,18 +504,16 @@ namespace VocaluxeLib.Menu.SongMenu { base._EnterCategory(categoryNr); - _PreviewNr = 0; SetSelectedSong(0); - _AfterCategoryChange(); + _UpdateListIfRequired(); } protected override void _LeaveCategory() { base._LeaveCategory(); - _PreviewNr = 0; SetSelectedCategory(0); - _AfterCategoryChange(); + _UpdateListIfRequired(); } 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; _LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex(); - _LastKnownNumSongs = CBase.Songs.GetNumSongsVisible(); + _LastKnownElements = curElements; CBase.Songs.UpdateRandomSongList(); _UpdateList(true); } 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) @@ -568,7 +568,7 @@ namespace VocaluxeLib.Menu.SongMenu bool isInCategory = CBase.Songs.IsInCategory(); 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) return; diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index 7c18a981..334089d2 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -240,7 +240,7 @@ namespace VocaluxeLib.Songs break; case "LANGUAGE": if (value.Length > 1) - _Song.Languages.Add(value); + _Song.Languages.Add(_UnifyLanguage(value)); else _LogWarning("Invalid language"); break; @@ -449,6 +449,27 @@ namespace VocaluxeLib.Songs 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 { Normal, diff --git a/WebserverInitalConfig/CConfigHttpApi.cs b/WebserverInitalConfig/CConfigHttpApi.cs index e13a9cda..90bdfc2b 100644 --- a/WebserverInitalConfig/CConfigHttpApi.cs +++ b/WebserverInitalConfig/CConfigHttpApi.cs @@ -60,9 +60,10 @@ namespace WebserverInitalConfig 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) diff --git a/WebserverInitalConfig/HttpApi.cs b/WebserverInitalConfig/HttpApi.cs index 39f587ff..6473afea 100644 --- a/WebserverInitalConfig/HttpApi.cs +++ b/WebserverInitalConfig/HttpApi.cs @@ -25,6 +25,7 @@ using System.Security.Cryptography.X509Certificates; namespace WebserverInitalConfig { + // ReSharper disable InconsistentNaming static class HttpApi { private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0); @@ -144,6 +145,14 @@ namespace WebserverInitalConfig 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)] public struct HTTP_SERVICE_CONFIG_URLACL_KEY { @@ -227,7 +236,7 @@ namespace WebserverInitalConfig if (retVal == ERROR_FILE_NOT_FOUND) return; - if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 + if (ERROR_INSUFFICIENT_BUFFER == retVal) { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); @@ -431,7 +440,7 @@ namespace WebserverInitalConfig IntPtr.Zero); if (ERROR_NO_MORE_ITEMS == retVal) break; - if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 + if (ERROR_INSUFFICIENT_BUFFER == retVal) { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); @@ -485,6 +494,101 @@ namespace WebserverInitalConfig 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) { if (String.IsNullOrEmpty(networkURL)) @@ -495,7 +599,7 @@ namespace WebserverInitalConfig CallHttpApi( 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_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); @@ -514,13 +618,15 @@ namespace WebserverInitalConfig Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); - if (ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183 + if (ERROR_ALREADY_EXISTS == retVal) { - retVal = HttpDeleteServiceConfiguration(IntPtr.Zero, - HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, - pInputConfigInfo, - Marshal.SizeOf(inputConfigInfoSet), - IntPtr.Zero); + retVal = DeleteReservation(networkURL); + if (ERROR_FILE_NOT_FOUND == retVal) + { + string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") : + networkURL.Replace("http", "https"); + retVal = DeleteReservation(networkURLOld); + } if (NOERROR == retVal) { @@ -530,41 +636,11 @@ namespace WebserverInitalConfig Marshal.SizeOf(inputConfigInfoSet), 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 { Marshal.FreeCoTaskMem(pInputConfigInfo); - HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero); } if (NOERROR != retVal) ThrowWin32ExceptionIfError(retVal); diff --git a/WebserverInitalConfig/Program.cs b/WebserverInitalConfig/Program.cs index d37f51f9..2223c5e8 100644 --- a/WebserverInitalConfig/Program.cs +++ b/WebserverInitalConfig/Program.cs @@ -30,25 +30,29 @@ namespace WebserverInitalConfig private static void Main(string[] args) // ReSharper restore InconsistentNaming { + int result = 0; try { 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"); - Environment.Exit(-1); + Console.WriteLine("Usage: VocaluxeServerConfig exeName port isHttps [reserve]"); + result = -1; } 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 { config.AddFirewallRule(); - if (args[1].ToLower() == "true") + if (isSecure) config.CreateAndAddCert(Dns.GetHostName()); - if ((args.Length >= 3 && args[2] == "reserve") || CConfigHttpApi.IsAdministrator()) - config.ReserveUrl(); + if (doReserve || CConfigHttpApi.IsAdministrator()) + config.ReserveUrl(isSecure); } catch (AuthenticationException) { @@ -56,8 +60,8 @@ namespace WebserverInitalConfig { UseShellExecute = true, WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, - FileName = Process.GetCurrentProcess().MainModule.FileName, - Arguments = args[0] + " " + args[1], + FileName = AppDomain.CurrentDomain.FriendlyName, + Arguments = String.Join(" ", args), Verb = "runas", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, @@ -65,21 +69,28 @@ namespace WebserverInitalConfig try { - Process.Start(proc); + using (Process p = Process.Start(proc)) + { + p.WaitForExit(); + result = p.ExitCode; + p.Close(); + } } catch { // The user refused the elevation. // Do nothing and return directly ... - Environment.Exit(-1); + result = -3; } } } } 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); } } } \ No newline at end of file