private void CreateWorld(CreateWorldForm form, int numMutants, int mutantSize) { try { Directory.CreateDirectory(worldPath); var connectionString = new SQLiteConnectionStringBuilder() { DataSource = dbPath }.ConnectionString; var conn = new SQLiteConnection(connectionString); conn.Open(); dbContext = new WorldDbContext(conn, false); dbContext.Create(numMutants, mutantSize); mutantManager = new MutantManager(dbContext, worldPath); mutantManager.CreateMutants( x => { form.Progress = x; Application.DoEvents(); }); form.Closed -= OnCreateWorldFormClosed; ShowWorld(); form.Close(); } catch (Exception e) { DestroyWorld(); while (e.InnerException != null) { e = e.InnerException; } MessageBox.Show("Coulnd't create or open db file, because " + e.Message, "Fatal Error"); Environment.Exit(-1); } }
public EvolverApplicationContext() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; worldPath = Path.Combine(Application.StartupPath, "world"); dbPath = Path.Combine(worldPath, "world.db"); if (Directory.Exists(worldPath)) { try { Directory.CreateDirectory(worldPath); var connectionString = new SQLiteConnectionStringBuilder() { DataSource = dbPath }.ConnectionString; var conn = new SQLiteConnection(connectionString); conn.Open(); dbContext = new WorldDbContext(conn, true); mutantManager = new MutantManager(dbContext, worldPath); mutantManager.LoadMutants(); ShowWorld(); } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } MessageBox.Show("Failed to load world: " + e.Message, "Fatal Error"); Environment.Exit(-1); } } else { var createWorldForm = new CreateWorldForm(); createWorldForm.Closed += OnCreateWorldFormClosed; createWorldForm.CreateWorldHandler = CreateWorld; createWorldForm.Show(); } }