/// <summary> /// Registeres a new File to the Storage. /// </summary> /// <param name="file"></param> public void RegisterFile(string file) { lock (this) { if (scannedFiles.Contains(file.ToLower())) { return; } // Kick den alten if (configuration.KnownFiles.Contains(file.ToLower())) { UnregisterFile(file); } var result = AiAnalysis.Analyse(file, true); if (result.Count > 0) { configuration.KnownFiles.Add(file.ToLower()); foreach (var player in result) { var playerInfo = new PlayerInfoFilename(player, file.ToLower()); knownPlayer.Add(playerInfo); } } SaveConfiguration(); } }
/// <summary> /// Adds all included Player without adding to the registered files. /// </summary> /// <param name="file"></param> private void ScanFile(string file) { try { var result = AiAnalysis.Analyse(file.ToLower(), false); foreach (var player in result) { knownPlayer.Add(new PlayerInfoFilename(player, file)); } scannedFiles.Add(file.ToLower()); } catch (Exception) { throw; } }
public static List <PlayerInfo> GetAntsFromAssembly(string filename) { // Klassen, die Spielerinfos enthalten var languageBases = new List <Type>(); languageBases.Add( typeof(AntMe.Deutsch.Basisameise)); languageBases.Add( typeof(AntMe.English.BaseAnt)); List <PlayerInfo> result = new List <PlayerInfo>(); try { // DLL laden Assembly assembly = Assembly.LoadFile(filename); Type[] types; // Enthaltene Klassen möglichst fehlerfrei auslesen // Stets unsicher, da die DLL zur Laufzeit analysiert wird try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types.Where(x => x != null).ToArray(); } foreach (Type t in types) { // Alle Klassen auf mögliche Spieler prüfen if (languageBases.Contains(t.BaseType)) { try { // Simulations-DLL liest Attribute aus result.Add(AiAnalysis.FindPlayerInformation(filename, t.FullName)); } catch { } } } } catch (Exception e) { } return(result); }
/// <summary> /// Loads all players from filename and add them to the global player-list. /// </summary> /// <param name="filename">filename</param> /// <param name="knownOnly">if only known players should be added</param> /// <returns>true, if there was no Exception</returns> /// <param name="silent">starts silent start without error-messages</param> private List <PlayerInfoFilename> loadPlayerFile(string filename, bool knownOnly, bool silent) { List <PlayerInfo> foundPlayers = new List <PlayerInfo>(); List <PlayerInfoFilename> output = new List <PlayerInfoFilename>(); try { FileInfo file = new FileInfo(filename.ToLower()); // Load playerinfo try { foundPlayers.AddRange(AiAnalysis.Analyse(file.FullName, false)); } catch (Exception ex) { if (!silent) { showException(ex); } return(output); } // Add found players if (foundPlayers.Count > 0) { if (!config.knownPlayerFiles.Contains(file.FullName)) { config.knownPlayerFiles.Add(file.FullName); } bool found = false; foreach (PlayerInfo playerInfo in foundPlayers) { PlayerInfoFilename info = new PlayerInfoFilename(playerInfo, file.FullName); output.Add(info); if (!players.Contains(info)) { if (knownOnly) { if (!config.knownPlayer.Contains(info.GetHashCode())) { continue; } } else { if (!config.knownPlayer.Contains(info.GetHashCode())) { config.knownPlayer.Add(info.GetHashCode()); } } players.Add(info); found = true; } } if (!found && !knownOnly && !silent) { MessageBox.Show( this, string.Format(Resource.SimulatorPluginTeamSetupStillLoaded, file.FullName), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (!silent) { MessageBox.Show( this, string.Format(Resource.SimulatorPluginTeamSetupNoFolksFound, file.FullName), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { showException( new Exception( string.Format( Resource.SimulatorPluginTeamSetupFileloadException, filename, ex.Message), ex)); } UpdatePanel(); return(output); }