private string GetRelativeDirectory(string file) { string current = LauncherPath.GetDataDirectory(); if (file.Contains(current)) { string[] filePath = file.Split(Path.DirectorySeparatorChar); string[] currentPath = current.Split(Path.DirectorySeparatorChar); string[] relativePath = filePath.Except(currentPath).ToArray(); StringBuilder sb = new StringBuilder(); foreach (string str in relativePath) { sb.Append(str); sb.Append(Path.DirectorySeparatorChar); } if (sb.Length > 1) { sb.Remove(sb.Length - 1, 1); } return(sb.ToString()); } return(file); }
private bool VerifyDatabase() { bool check = false; try { if (File.Exists(Path.Combine(LauncherPath.GetDataDirectory(), DbDataSourceAdapter.DatabaseFileName))) { check = true; // Still attempt to delete the init database here for people that manually update (not installed) if (File.Exists(DbDataSourceAdapter.InitDatabaseFileName)) { File.Delete(DbDataSourceAdapter.InitDatabaseFileName); } return(check); } check = InitFileCheck(DbDataSourceAdapter.DatabaseFileName, DbDataSourceAdapter.InitDatabaseFileName, false); if (!check) { MessageBox.Show(this, "Initialization failure. Could not find DoomLauncher database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { Util.DisplayUnexpectedException(this, ex); } return(check); }
public void Init(IDataSourceAdapter adapter) { DataSourceAdapter = adapter; AppConfiguration = new AppConfiguration(adapter); TagMapLookup = new TagMapLookup(adapter); DefaultImage = Image.FromFile(Path.Combine(LauncherPath.GetDataDirectory(), "TileImages", "DoomLauncherTile.png")); UpdateTags(); }
private void CleanupBackupDirectory() { string[] files = Directory.GetFiles(Path.Combine(LauncherPath.GetDataDirectory(), "Backup"), "*.sqlite"); List <FileInfo> filesInfo = new List <FileInfo>(); Array.ForEach(files, x => filesInfo.Add(new FileInfo(x))); List <FileInfo> filesInfoOrdered = filesInfo.OrderBy(x => x.CreationTime).ToList(); while (filesInfoOrdered.Count > 10) { filesInfoOrdered.First().Delete(); filesInfoOrdered.RemoveAt(0); } }
public void Pre_0_9_2() { DataTable dt = DataAccess.ExecuteSelect("select name from sqlite_master where type='table' and name='Configuration';").Tables[0]; if (dt.Rows.Count == 0) { string query = @"CREATE TABLE 'Configuration' ( 'ConfigID' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'Name' TEXT NOT NULL, 'Value' TEXT NOT NULL, 'AvailableValues' TEXT NOT NULL, 'UserCanModify' INTEGER);" ; DataAccess.ExecuteNonQuery(query); query = string.Format(@"insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('IdGamesUrl', 'http://www.doomworld.com/idgames/', '', 1); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('ApiPage', 'api/api.php', '', 1); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('MirrorUrl', 'ftp://mancubus.net/pub/idgames/', 'Germany;ftp://ftp.fu-berlin.de/pc/games/idgames/;Idaho;ftp://mirrors.syringanetworks.net/idgames/;Greece;ftp://ftp.ntua.gr/pub/vendors/idgames/;Texas;ftp://mancubus.net/pub/idgames/;New York;http://youfailit.net/pub/idgames/;Florida;http://www.gamers.org/pub/idgames/;', 1); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('ScreenshotCaptureDirectories', '', '', 1); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('DateParseFormats', 'dd/M/yy;dd/MM/yyyy;dd MMMM yyyy;', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('CleanTemp', 'true', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('GameFileDirectory', '{0}', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('ScreenshotDirectory', '{1}', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('TempDirectory', '{2}', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('GameWadDirectory', '{3}', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('DemoDirectory', '{4}', '', 0); insert into Configuration (Name, Value, AvailableValues, UserCanModify) values('SaveGameDirectory', '{5}', '', 0);", ConfigurationManager.AppSettings["GameFileDirectory"], ConfigurationManager.AppSettings["ScreenshotDirectory"], ConfigurationManager.AppSettings["TempDirectory"], ConfigurationManager.AppSettings["GameWadDirectory"], ConfigurationManager.AppSettings["DemoDirectory"], ConfigurationManager.AppSettings["GameFileDirectory"] + "SaveGames\\"); DataAccess.ExecuteNonQuery(query); DirectoryInfo di = new DirectoryInfo(Path.Combine(LauncherPath.GetDataDirectory(), ConfigurationManager.AppSettings["GameFileDirectory"], "SaveGames")); if (!di.Exists) { di.Create(); } } dt = DataAccess.ExecuteSelect("pragma table_info(Files);").Tables[0]; if (!dt.Select("name = 'OriginalFileName'").Any()) { string query = @"alter table Files add column 'OriginalFileName' TEXT; alter table Files add column 'OriginalFilePath' TEXT;"; DataAccess.ExecuteNonQuery(query); } }
private static LauncherPath GetGameFileDir(string gameFileDir) { if (gameFileDir == "GameFiles\\") { string dataDir = LauncherPath.GetDataDirectory(); if (!Directory.Exists(dataDir)) { Directory.CreateDirectory(dataDir); Directory.CreateDirectory(Path.Combine(dataDir, gameFileDir)); } return(new LauncherPath(Path.Combine(dataDir, gameFileDir))); } return(new LauncherPath(gameFileDir)); }
private async Task Initialize() { string dataSource = Path.Combine(LauncherPath.GetDataDirectory(), DbDataSourceAdapter.DatabaseFileName); DataAccess access = new DataAccess(new SqliteDatabaseAdapter(), DbDataSourceAdapter.CreateConnectionString(dataSource)); m_versionHandler = new VersionHandler(access, DbDataSourceAdapter.CreateAdapter(true), AppConfiguration); if (m_versionHandler.UpdateRequired()) { m_versionHandler.UpdateProgress += handler_UpdateProgress; m_progressBarUpdate = CreateProgressBar("Updating...", ProgressBarStyle.Continuous); ProgressBarStart(m_progressBarUpdate); await Task.Run(() => ExecuteVersionUpdate()); ProgressBarEnd(m_progressBarUpdate); AppConfiguration.Refresh(); //We have to refresh here because a column may have been added to the Configuration table } if (AppConfiguration.CleanTemp) { CleanTempDirectory(); } DirectoryDataSourceAdapter = new DirectoryDataSourceAdapter(AppConfiguration.GameFileDirectory); DataCache.Instance.Init(DataSourceAdapter); DataCache.Instance.AppConfiguration.GameFileViewTypeChanged += AppConfiguration_GameFileViewTypeChanged; DataCache.Instance.TagMapLookup.TagMappingChanged += TagMapLookup_TagMappingChanged; DataCache.Instance.TagsChanged += DataCache_TagsChanged; CleanUpFiles(); SetupTabs(); RebuildUtilityToolStrip(); BuildUtilityToolStrip(); InitTagSelectControl(); InitDownloadView(); ctrlAssociationView.Initialize(DataSourceAdapter, AppConfiguration); ctrlAssociationView.FileDeleted += ctrlAssociationView_FileDeleted; ctrlAssociationView.FileOrderChanged += ctrlAssociationView_FileOrderChanged; ctrlAssociationView.RequestScreenshots += CtrlAssociationView_RequestScreenshots; }
private void BackupDatabase(string dataSource) { FileInfo fi = new FileInfo(dataSource); if (fi.Exists) { Directory.CreateDirectory(Path.Combine(LauncherPath.GetDataDirectory(), "Backup")); string backupName = GetBackupFileName(fi); FileInfo fiBackup = new FileInfo(backupName); if (!fiBackup.Exists) { fi.CopyTo(backupName); } CleanupBackupDirectory(); } }
private async void Initialize() { string dataSource = Path.Combine(LauncherPath.GetDataDirectory(), DbDataSourceAdapter.DatabaseFileName); DataAccess access = new DataAccess(new SqliteDatabaseAdapter(), DbDataSourceAdapter.CreateConnectionString(dataSource)); m_versionHandler = new VersionHandler(access, DbDataSourceAdapter.CreateAdapter(true), AppConfiguration); if (m_versionHandler.UpdateRequired()) { m_versionHandler.UpdateProgress += handler_UpdateProgress; m_progressBarUpdate = CreateProgressBar("Updating...", ProgressBarStyle.Continuous); ProgressBarStart(m_progressBarUpdate); await Task.Run(() => ExecuteVersionUpdate()); ProgressBarEnd(m_progressBarUpdate); AppConfiguration.Refresh(); //We have to refresh here because a column may have been added to the Configuration table } try { //Only set location and window state if the location is valid, either way we always set Width, Height, and splitter values if (ValidatePosition(AppConfiguration)) { WindowState = AppConfiguration.WindowState; if (WindowState != FormWindowState.Maximized) { StartPosition = FormStartPosition.Manual; Location = new Point(AppConfiguration.AppX, AppConfiguration.AppY); } } // Save the height and set after splitter, otherwise splitter resizing will be incorrect int saveWidth = Width; int saveHeight = Height; Width = AppConfiguration.AppWidth; Height = AppConfiguration.AppHeight; splitTopBottom.SplitterDistance = AppConfiguration.SplitTopBottom; splitLeftRight.SplitterDistance = AppConfiguration.SplitLeftRight; // If the app was closed in the maximized state then the width and height are maxed out // This causes the window to take up the full screen even when set to normal state if (WindowState == FormWindowState.Maximized) { Width = saveWidth; Height = saveHeight; } } catch (DirectoryNotFoundException ex) { MessageBox.Show(this, string.Format("The directory specified in your settings was incorrect: '{0}'", ex.Message), "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tblMain.Enabled = false; return; } if (AppConfiguration.CleanTemp) { CleanTempDirectory(); } DirectoryDataSourceAdapter = new DirectoryDataSourceAdapter(AppConfiguration.GameFileDirectory); DataCache.Instance.Init(DataSourceAdapter); DataCache.Instance.AppConfiguration.GameFileViewTypeChanged += AppConfiguration_GameFileViewTypeChanged; SetupTabs(); RebuildUtilityToolStrip(); BuildUtilityToolStrip(); m_downloadView = new DownloadView(); m_downloadView.UserPlay += DownloadView_UserPlay; m_downloadHandler = new DownloadHandler(AppConfiguration.TempDirectory, m_downloadView); ctrlAssociationView.Initialize(DataSourceAdapter, AppConfiguration); ctrlAssociationView.FileDeleted += ctrlAssociationView_FileDeleted; ctrlAssociationView.FileOrderChanged += ctrlAssociationView_FileOrderChanged; ctrlAssociationView.RequestScreenshots += CtrlAssociationView_RequestScreenshots; m_splash.Close(); await CheckFirstInit(); UpdateLocal(); SetupSearchFilters(); await Task.Run(() => CheckForAppUpdate()); }
public static IDataSourceAdapter CreateAdapter(bool outOfDateDatabase) { string databaseFile = Path.Combine(LauncherPath.GetDataDirectory(), DatabaseFileName); return(new DbDataSourceAdapter(new SqliteDatabaseAdapter(), CreateConnectionString(databaseFile), outOfDateDatabase)); }