From: <nor...@us...> - 2007-08-16 10:37:22
|
Revision: 842 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=842&view=rev Author: northern_sky Date: 2007-08-16 03:36:15 -0700 (Thu, 16 Aug 2007) Log Message: ----------- more cleanups, fixed gamebaseimport,baseitem rem, abstact appitem instead Modified Paths: -------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Database/DatabaseHandler.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/AppFilesView.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.Designer.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SetupForm.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/GamebaseImport.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemFactory.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGrouper.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FileItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FilelinkItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FilterItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramUtils.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramViewHandler.cs Removed Paths: ------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/BaseItem.cs Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Database/DatabaseHandler.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Database/DatabaseHandler.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Database/DatabaseHandler.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -49,6 +49,9 @@ { #region Variables + private ProgramViewHandler ViewHandler = ProgramViewHandler.Instance; + private ItemFactory itemFactoryInstance = ItemFactory.ItemFactoryInstance; + private SQLiteConnection sqlLiteConnection = null; private List<ApplicationItem> globalApplicationItemList = new List<ApplicationItem>(); private readonly string DATABASEFILE = "myProgramsAltDatabaseV1.db3"; @@ -66,8 +69,8 @@ { string DatabasePath = Config.GetFile(Config.Dir.Database, DATABASEFILE); string connString = string.Empty; - - try + + try { //check if database exists if (!File.Exists(DatabasePath)) @@ -263,7 +266,6 @@ public ItemType GetItemType(string columnName, string tableName, int id) { - ItemType itemType = ItemType.UNKNOWN; string sqlStmt = "SELECT " + columnName + " FROM " + tableName + " WHERE applicationId = " + id; return ProgramUtils.StringToSourceType(ExecuteStmtScalar(sqlStmt).ToString()); @@ -378,6 +380,51 @@ #endregion dataaccess help methods + + public List<object> LoadItemList(int appID,List<object> itemList, string overrideSQL) + { + try + { + itemList.Clear(); + string sqlQuery = ""; + + if (overrideSQL == "") + { + sqlQuery = ViewHandler.BuildQuery(appID); + } + else + { + sqlQuery = overrideSQL; + } + + using (SQLiteCommand command = SqlLiteConn.CreateCommand()) + { + command.CommandText = sqlQuery; + using (SQLiteDataReader dataReader = command.ExecuteReader()) + { + while (dataReader.Read()) + { + if (ViewHandler.IsFilterQuery) + { + FilterItem curFile = (FilterItem)itemFactoryInstance.GetItem(ItemType.FILTERITEM, dataReader); + itemList.Add(curFile); + } + else + { + FileItem curFile = (FileItem)itemFactoryInstance.GetItem(ItemType.FILEITEM, dataReader); + itemList.Add(curFile); + } + } + } + } + } + catch (SQLiteException ex) + { + Log.Info("Filedatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + return itemList; + } + public void LoadAllApplicationItems() { Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/AppFilesView.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/AppFilesView.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/AppFilesView.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -111,7 +111,7 @@ fileListView.Items.Clear(); - foreach (BaseItem item in currentApplication.ItemList) + foreach (object item in currentApplication.ItemList) { // add all filelinks, // or add all files @@ -254,16 +254,11 @@ if (dialogResult == DialogResult.OK) { file.Write(); - currentApplication.ItemLoad(currentApplication.ApplicationItemId, ""); + currentApplication.LoadFiles(); SyncListView(); } } - private void ChangeFilePath(string NewPath) - { - currentApplication.ItemLoad(currentApplication.ApplicationItemId, NewPath); - SyncListView(); - } private void EditItem() { @@ -279,7 +274,7 @@ if (dialogResult == DialogResult.OK) { file.Write(); - currentApplication.ItemLoad(currentApplication.ApplicationItemId, ""); + currentApplication.LoadFiles(); SyncListView(); } } @@ -330,7 +325,7 @@ } } } - currentApplication.ItemLoad(currentApplication.ApplicationItemId, ""); + currentApplication.LoadFiles(); SyncListView(); } @@ -564,7 +559,7 @@ // Log.Info("Add to Favourites groupAppID:{0} Title:{1} fileID:{2} appID:{3}", GrouperAppID, currentFileItem.Title, currentFileItem.FileID, currentFileItem.applicationId); } - foreach (BaseItem app in apps) + foreach (object app in apps) { if (app is ApplicationItemGrouper) { Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.Designer.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.Designer.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.Designer.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -36,6 +36,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Name = "SettingsBase"; this.Size = new System.Drawing.Size(497, 550); + this.Load += new System.EventHandler(this.SettingsBase_Load); this.ResumeLayout(false); } Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SettingsBase.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -44,7 +44,7 @@ public partial class SettingsBase : UserControl { protected ConditionChecker conditionChecker = new ConditionChecker(); - protected DatabaseHandler dbHandlerInstance = DatabaseHandler.DBHandlerInstance; + protected DatabaseHandler dbHandlerInstance; public SettingsBase() @@ -68,5 +68,14 @@ //Log.Debug("{0}: EntriesOK()", this.ToString()); return true; } + + private void SettingsBase_Load(object sender, EventArgs e) + { + //temp fix for vs designer support + //vs design can be errorunos if using static help methods in contructor etc . databasehandler does + if(!DesignMode) { + dbHandlerInstance = DatabaseHandler.DBHandlerInstance; + } + } } } \ No newline at end of file Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SetupForm.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SetupForm.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/SetupForm.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -20,36 +20,7 @@ #endregion -//#region Enums -//#endregion -//#region Delegates -//#endregion - -//#region Events -//#endregion - - - - - -#region Properties -// Public Properties -#endregion - -#region Public Methods -#endregion - -#region Private Methods -#endregion - -#region <Base class> Overloads -#endregion - -#region <Interface> Implementations -// region for each interface -#endregion - namespace GUIPrograms.Design { public partial class SetupForm : Form @@ -57,6 +28,7 @@ #region Variables + private DatabaseHandler dbHandlerInstance = DatabaseHandler.DBHandlerInstance; private List<ApplicationItem> globalApplicationList;// = DatabaseHandler.DBHandlerInstance.ApplicationItemList; private AppSettingsDirCache appSettingsDirCache = new AppSettingsDirCache(); @@ -633,7 +605,7 @@ { AppSettingsBase appSettingsPage = pageCurrentSettings as AppSettingsBase; // create a pseudo-appitem and read the values from the xml node - ApplicationItem tempApp = new ApplicationItem(); + ApplicationItemDirectoryCache tempApp = new ApplicationItemDirectoryCache(); tempApp.LoadFromXmlProfile(node); appSettingsPage.LoadFromAppItem(tempApp); appSettingsFileEditView.FileExtensionsText = tempApp.ValidExtensions; @@ -723,6 +695,9 @@ private void SetupForm_Load(object sender, EventArgs e) { + + + AttachFilesView(); AttachProgramsView(); UpdateTree(); Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -305,7 +305,7 @@ } xmlwriter.SetValue("myprograms", "startWindow", StartWindow.ToString()); - xmlwriter.SetValue("myprograms", "startview", (int) mapSettings.ViewLayout); + xmlwriter.SetValue("myprograms", "startview", (int)mapSettings.ViewLayout); } } @@ -452,7 +452,7 @@ prevFilepath = lastApp.DefaultFilepath(); this.CurrentSortAsc = mapSettings.SortAscending; ViewHandler.CurrentLevel = mapSettings.LastViewLevel; - lastApp.ViewHandler = this.ViewHandler; + //lastApp.ViewHandler = this.ViewHandler; } else { @@ -797,7 +797,7 @@ switch (CurrentSortMethod) { - case ProgramSort.SortMethod.Title: + case ProgramSort.SortMethod.Title: sortBy = GUILocalizeStrings.Get(268); break; case ProgramSort.SortMethod.Filename: @@ -925,8 +925,8 @@ lastApp.LoadFiles(); lastApp.CurrentView = ViewHandler.CurrentView; } - - int totalFiles = lastApp.DisplayFiles(lastApp.FileDirectory, facadeView); + int totalFiles = 0; + totalFiles = totalFiles + DisplayItemList(lastApp.filePath, lastApp.ItemList, facadeView); return (totalFiles); } @@ -1216,6 +1216,19 @@ } } + /* protected void OnItemSelected(GUIListItem item, GUIControl parent) + { + GUIPrograms.ThumbnailPath = ""; + if (item.ThumbnailImage != "" + && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png" + && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultAlbum.png" + ) + { + // only show big thumb if there is really one.... + GUIPrograms.ThumbnailPath = item.ThumbnailImage; + } + }*/ + void OnItemSelected(GUIListItem item, GUIControl parent) { ThumbnailPath = ""; @@ -1236,15 +1249,52 @@ void OnClick() { - GUIListItem item = GetSelectedItem(); + GUIListItem selectedGUIListItem = GetSelectedItem(); - if (item.MusicTag != null) + if (selectedGUIListItem.MusicTag != null) { - ((BaseItem)item.MusicTag).OnClick((BaseItem)item.MusicTag, this); + object item = selectedGUIListItem.MusicTag; + + if (item is ApplicationItem) + { + + lastApp = (ApplicationItem)item; + SaveItemIndex(GetSelectedItemNo().ToString(), lastApp, lastApp.lastFilepath); + mapSettings.LastAppID = lastApp.ApplicationItemId; + prevFilepath = lastApp.DefaultFilepath(); + ViewHandler.CurrentLevel = 0; + //lastApp.ViewHandler = ViewHandler; + } + else if (item is FileItem) + { + FileItem fileItem = (FileItem)item; + selectedItemIndex = GetSelectedItemNo(); + + if (lastApp != null) + { + mapSettings.LastAppID = lastApp.ApplicationItemId; + prevFilepath = lastApp.DefaultFilepath(); + lastApp.LaunchFile(fileItem); + } + } + else if (item is FilterItem) + { + FilterItem filterItem = (FilterItem)item; + + SaveItemIndex(GetSelectedItemNo().ToString(), lastApp, prevFilepath); + ViewHandler.AddFilterItem(filterItem); + if (lastApp != null) + { + // force reload, this will load the next filter-level..... + lastApp.LoadFiles(); + } + } + + UpdateButtonStates(); UpdateListControl(); } - else if (item.Label.Equals(ProgramUtils.cBackLabel)) + else if (selectedGUIListItem.Label.Equals(ProgramUtils.cBackLabel)) { // folder-item clicked.... selectedItemIndex = -1; BackItemClicked(); @@ -1252,6 +1302,69 @@ } } + #region moved from BaseItem + + public int DisplayItemList(string filePath, List<object> dbItems, GUIFacadeControl facadeView) + { + int totalItems = 0; + + foreach (object baseItem in dbItems) + { + totalItems = totalItems + 1; + + if (baseItem is FileItem) + { + FileItem curFile = baseItem as FileItem; + GUIListItem gli = new GUIListItem(curFile.Title); + + gli.MusicTag = curFile; + // gli.IsFolder = curFile.IsFolder; + gli.OnRetrieveArt += new MediaPortal.GUI.Library.GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt); + gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); + facadeView.Add(gli); + } + if (baseItem is FilterItem) + { + FilterItem curFile = baseItem as FilterItem; + GUIListItem gli = new GUIListItem(curFile.Title); + gli.MusicTag = curFile; + //gli.IsFolder = false; + gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); + facadeView.Add(gli); + } + } + return totalItems; + } + + protected void OnRetrieveCoverArt(GUIListItem guiListItem) + { + if (guiListItem.MusicTag == null) return; + FileItem curFileItem = (FileItem)guiListItem.MusicTag; + if (curFileItem == null) return; + + string imgFile = String.Empty; + + if (ProgramUtils.UseThumbsDir()) + imgFile = ProgramUtils.GetFileImage(lastApp, curFileItem); + else + imgFile = curFileItem.Imagefile; + + if (File.Exists(imgFile)) + { + guiListItem.ThumbnailImage = imgFile; + guiListItem.IconImageBig = imgFile; + guiListItem.IconImage = imgFile; + } + else + { + guiListItem.ThumbnailImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; + guiListItem.IconImageBig = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; + guiListItem.IconImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderNF.png"; + } + } + + #endregion + protected void OnShowSort() { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); @@ -1288,15 +1401,15 @@ default: CurrentSortMethod = ProgramSort.SortMethod.Title; break; - } + } //ToDo //tmp fix until all mappings in place. - switch (dlg.SelectedLabelText) + switch (dlg.SelectedLabelText) { case "Sort by: Times launched": CurrentSortMethod = ProgramSort.SortMethod.LaunchCount; break; - case "Sort by: Date launched": + case "Sort by: Date launched": CurrentSortMethod = ProgramSort.SortMethod.LastTimeLaunched; break; case "Sort by: Platform": @@ -1304,9 +1417,9 @@ break; default: break; - } - + } + OnSort(); GUIControl.FocusControl(GetID, btnSortBy.GetID); } @@ -1330,7 +1443,7 @@ if (item.Label.Equals(ProgramUtils.cBackLabel)) return; if (item.MusicTag == null) return; if (item.MusicTag is ApplicationItem) return; - + if (item.MusicTag is FileItem) { curFile = (FileItem)item.MusicTag; @@ -1378,7 +1491,7 @@ { int nNewWindow = (int)Window.WINDOW_FILES; StartWindow = nNewWindow; - mapSettings.ViewLayout = (int) Layout.List; + mapSettings.ViewLayout = (int)Layout.List; ViewHandler.CurrentView = GUILocalizeStrings.Get(100000 + GetID);//my files if (nNewWindow != GetID) { Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj 2007-08-16 10:36:15 UTC (rev 842) @@ -145,7 +145,6 @@ <Compile Include="Items\ApplicationItemGameBase.cs" /> <Compile Include="Items\ApplicationItemGrouper.cs" /> <Compile Include="Items\ApplicationItemMame.cs" /> - <Compile Include="Items\BaseItem.cs" /> <Compile Include="Items\FileItem.cs" /> <Compile Include="Items\FileItemInfo.cs" /> <Compile Include="Items\FilelinkItem.cs" /> Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/GamebaseImport.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/GamebaseImport.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/GamebaseImport.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -32,6 +32,7 @@ using GUIPrograms.Items; using GUIPrograms; using GUIPrograms.Database; +using System.Data.SQLite; namespace GUIPrograms.Imports @@ -60,6 +61,7 @@ void DBImportGamebaseItem(OleDbDataReader myReader, string romFilename, string imgFilename, int curPos, int maxGames) { + FileItem curFile = new FileItem(); curFile.FileID = -1; // to force an INSERT statement when writing the item curFile.AppID = applicationItem.ApplicationItemId; @@ -142,64 +144,69 @@ { using (OleDbConnection myCon = new OleDbConnection(strCon)) { - using (OleDbTransaction transaction = myCon.BeginTransaction()) - { + using (OleDbCommand myCmd = new OleDbCommand(sqlStr, myCon)) { + using (SQLiteTransaction transaction = DatabaseHandler.DBHandlerInstance.SqlLiteConn.BeginTransaction()) + + { myCon.Open(); int maxGames = CountGames(myCon, sqlStrCount); - using (OleDbDataReader myReader = myCmd.ExecuteReader()) - { + + + using (OleDbDataReader myReader = myCmd.ExecuteReader()) + { - int i = 0; - while (myReader.Read()) - { - i++; - curRomname = myReader["Filename"].ToString(); - curFullRomname = applicationItem.FileDirectory + "\\" + curRomname; + int i = 0; + while (myReader.Read()) + { + i++; + curRomname = myReader["Filename"].ToString(); + curFullRomname = applicationItem.FileDirectory + "\\" + curRomname; - if (applicationItem.ImageDirectory != "") - { - curTitleImage = applicationItem.imageDirs[0] + "\\" + myReader["ScrnshotFilename"].ToString(); - } - else - { - curTitleImage = ""; - } + if (applicationItem.ImageDirectory != "") + { + curTitleImage = applicationItem.imageDirs[0] + "\\" + myReader["ScrnshotFilename"].ToString(); + } + else + { + curTitleImage = ""; + } - if (File.Exists(curFullRomname)) - { - // rom-name from gamebase exists in users filedirectory - // => ready to import item - bDoImport = true; + if (File.Exists(curFullRomname)) + { + // rom-name from gamebase exists in users filedirectory + // => ready to import item + bDoImport = true; - if (applicationItem.ImportValidImagesOnly) - { - // skip item if no thumbnail image is found - bDoImport = ((curTitleImage != null) && (curTitleImage != "") && (File.Exists(curTitleImage))); - } + if (applicationItem.ImportValidImagesOnly) + { + // skip item if no thumbnail image is found + bDoImport = ((curTitleImage != null) && (curTitleImage != "") && (File.Exists(curTitleImage))); + } + + if (bDoImport) + { + DBImportGamebaseItem(myReader, curFullRomname, curTitleImage, i, maxGames); - if (bDoImport) - { - DBImportGamebaseItem(myReader, curFullRomname, curTitleImage, i, maxGames); + } + else + { + Log.Info("*skipped* gamebase game {0} image{1}", curRomname, curTitleImage); + } + } + else + { + Log.Info("*missing* gamebase game {0}", curRomname); + } } - else - { - Log.Info("*skipped* gamebase game {0} image{1}", curRomname, curTitleImage); - } - } - else - { - Log.Info("*missing* gamebase game {0}", curRomname); - } + transaction.Commit(); } - } - } - transaction.Commit(); + } } } Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs 2007-08-16 05:22:46 UTC (rev 841) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs 2007-08-16 10:36:15 UTC (rev 842) @@ -23,6 +23,8 @@ #endregion +#region Imports + using System; using System.Collections.Generic; using System.Diagnostics; @@ -41,761 +43,644 @@ using GUIPrograms.Database; using GUIPrograms.Items; +#endregion Imports namespace GUIPrograms.Items { - public class ApplicationItem : BaseItem - { - #region Variables + public abstract class ApplicationItem + { + #region Events/Delegates - int appID; - int fatherID; - string title; - string filename; + public delegate void FilelinkLaunchEventHandler(FilelinkItem curLink, bool mpGuiMode); + public event FilelinkLaunchEventHandler OnLaunchFilelink = null; - string arguments; - ProcessWindowStyle windowStyle; - string startupDir; - bool useQuotes; - bool useShellExecute; - bool waitForExit; - string preLaunch; - string postLaunch; + // event: read new file + public delegate void RefreshInfoEventHandler(string informationMessage, int progressBarProgess); + public event RefreshInfoEventHandler OnRefreshInfo = null; + #endregion Events/Delegates - private List<ImportOption> importOptionList; + #region Variables - public List<ImportOption> ImportOptionList - { - get { return importOptionList; } - set { importOptionList = value; } - } - bool enabled; - int appPosition; + protected int GetID = ProgramUtils.GetID; + protected DatabaseHandler dbHandlerInstance = DatabaseHandler.DBHandlerInstance; - string currentView = ""; + int appID; + int fatherID; + string title; + string filename; - public List<BaseItem> ItemList = new List<BaseItem>(); - public bool filesAreLoaded = false; // load on demand.... - // protected FileItemList fileList = null; + string arguments; + ProcessWindowStyle windowStyle; + string startupDir; + bool useQuotes; + bool useShellExecute; + bool waitForExit; + string preLaunch; + string postLaunch; + private List<ImportOption> importOptionList; + bool enabled; + int appPosition; - public bool linksAreLoaded = false; // load on demand.... + string currentView = ""; - bool importMamePlaychoice10 = false; - bool importMameMahjong = false; - bool refreshGUIAllowed = false; + public List<object> ItemList = new List<object>(); + public bool filesAreLoaded = false; // load on demand.... + public bool linksAreLoaded = false; // load on demand.... + bool importMamePlaychoice10 = false; + bool importMameMahjong = false; + bool refreshGUIAllowed = false; + public string filePath = ""; - ItemType sourceType; - string sourceFile; - string imageFile; - string imageDirectories; // in one string for sqlite db field - public string[] imageDirs; // imageDirectories splitted - string fileDirectory; - string validExtensions; - bool importValidImagesOnly; + ItemType sourceType; + string sourceFile; + string imageFile; + string imageDirectories; // in one string for sqlite db field + public string[] imageDirs; // imageDirectories splitted + string fileDirectory; + string validExtensions; + bool importValidImagesOnly; + int platformId; + string launchErrorMsg; + // two magic image-slideshow counters + int thumbIndex = 0; + int thumbFolderIndex = -1; - int platformId; + public string lastFilepath = ""; // cached path - string launchErrorMsg; - // two magic image-slideshow counters - int thumbIndex = 0; - int thumbFolderIndex = -1; + #endregion - protected string lastFilepath = ""; // cached path + #region Properties - #endregion + public List<ImportOption> ImportOptionList + { + get { return importOptionList; } + set { importOptionList = value; } + } - #region Properties - // Helper Routines + public int ApplicationItemId + { + get { return appID; } + set { appID = value; } + } + public int FatherID + { + get { return fatherID; } + set { fatherID = value; } + } + public string Title + { + get { return title; } + set { title = value; } + } + public string Filename + { + get { return filename; } + set { filename = value; } + } + public string Imagefile + { + get { return imageFile; } + set { imageFile = value; } + } - public int ApplicationItemId - { - get { return appID; } - set { appID = value; } - } - public int FatherID - { - get { return fatherID; } - set { fatherID = value; } - } - public string Title - { - get { return title; } - set { title = value; } - } + public string Arguments + { + get { return arguments; } + set { arguments = value; } + } + public ProcessWindowStyle WindowStyle + { + get { return windowStyle; } + set { windowStyle = value; } + } + public string StartupDir + { + get { return startupDir; } + set { startupDir = value; } + } + public bool UseQuotes + { + get { return useQuotes; } + set { useQuotes = value; } + } + public bool UseShellExecute + { + get { return useShellExecute; } + set { useShellExecute = value; } + } + public bool WaitForExit + { + get { return waitForExit; } + set { waitForExit = value; } + } + public string PreLaunch + { + get { return preLaunch; } + set { preLaunch = value; } + } + public string PostLaunch + { + get { return postLaunch; } + set { postLaunch = value; } + } - public string Filename - { - get { return filename; } - set { filename = value; } - } - public string Imagefile - { - get { return imageFile; } - set { imageFile = value; } - } + public bool Enabled + { + get { return enabled; } + set { enabled = value; } + } - public string Arguments - { - get { return arguments; } - set { arguments = value; } - } - public ProcessWindowStyle WindowStyle - { - get { return windowStyle; } - set { windowStyle = value; } - } - public string StartupDir - { - get { return startupDir; } - set { startupDir = value; } - } - public bool UseQuotes - { - get { return useQuotes; } - set { useQuotes = value; } - } - public bool UseShellExecute - { - get { return useShellExecute; } - set { useShellExecute = value; } - } - public bool WaitForExit - { - get { return waitForExit; } - set { waitForExit = value; } - } - public string PreLaunch - { - get { return preLaunch; } - set { preLaunch = value; } - } - public string PostLaunch - { - get { return postLaunch; } - set { postLaunch = value; } - } + public bool RefreshGUIAllowed + { + get { return refreshGUIAllowed; } + set { refreshGUIAllowed = value; } + } - public bool Enabled - { - get { return enabled; } - set { enabled = value; } - } + public int Position + { + get { return appPosition; } + set { appPosition = value; } + } - public virtual bool RefreshGUIAllowed - { - get { return refreshGUIAllowed; } - set { refreshGUIAllowed = value; } - } + public string CurrentView + { + get { return currentView; } + set { currentView = value; } + } - public int Position - { - get { return appPosition; } - set { appPosition = value; } - } + public bool ImportMamePlaychoice10 + { + get { return importMamePlaychoice10; } + set { importMamePlaychoice10 = value; } + } + public bool ImportMameMahjong + { + get { return importMameMahjong; } + set { importMameMahjong = value; } + } - public string CurrentView - { - get { return currentView; } - set { currentView = value; } - } + // more Properties, maybe need some renaming or anything else + public string FileDirectory + { + get { return fileDirectory; } + set { fileDirectory = value; } + } + public string ImageDirectory + { + get { return imageDirectories; } + set { SetImageDirectory(value); } + } + private void SetImageDirectory(string value) + { + imageDirectories = value; + imageDirs = imageDirectories.Split(';'); + for (int i = 0; i < imageDirs.Length; i++) + { + imageDirs[i] = imageDirs[i].Trim(); + // hack the \n away.... + // imageDirs[i] = imageDirs[i].TrimStart('\n'); + // hack trailing backslashes away + imageDirs[i] = imageDirs[i].TrimEnd('\\'); + } + } + public string Source + { + get { return sourceFile; } + set { sourceFile = value; } + } + public ItemType SourceType + { + get { return sourceType; } + set { sourceType = value; } + } + public string ValidExtensions + { + get { return validExtensions; } + set { validExtensions = value; } + } + public bool ImportValidImagesOnly + { + get { return importValidImagesOnly; } + set { importValidImagesOnly = value; } + } - public bool ImportMamePlaychoice10 - { - get { return importMamePlaychoice10; } - set { importMamePlaychoice10 = value; } - } - public bool ImportMameMahjong - { - get { return importMameMahjong; } - set { importMameMahjong = value; } - } + public int PlatformId + { + get { return platformId; } + set { platformId = value; } + } + public string LaunchErrorMsg + { + get { return launchErrorMsg; } + set { launchErrorMsg = value; } + } - // more Properties, maybe need some renaming or anything else - public string FileDirectory - { - get { return fileDirectory; } - set { fileDirectory = value; } - } - public string ImageDirectory - { - get { return imageDirectories; } - set { SetImageDirectory( value ); } - } - private void SetImageDirectory(string value) - { - imageDirectories = value; - imageDirs = imageDirectories.Split( ';' ); - for ( int i = 0; i < imageDirs.Length; i++ ) - { - imageDirs[i] = imageDirs[i].Trim(); - // hack the \n away.... - // imageDirs[i] = imageDirs[i].TrimStart('\n'); - // hack trailing backslashes away - imageDirs[i] = imageDirs[i].TrimEnd( '\\' ); - } - } - public string Source - { - get { return sourceFile; } - set { sourceFile = value; } - } - public ItemType SourceType - { - get { return sourceType; } - set { sourceType = value; } - } - public string ValidExtensions - { - get { return validExtensions; } - set { validExtensions = value; } - } - public bool ImportValidImagesOnly - { - get { return importValidImagesOnly; } - set { importValidImagesOnly = value; } - } + #endregion - public int PlatformId - { - get { return platformId; } - set { platformId = value; } - } - public string LaunchErrorMsg - { - get { return launchErrorMsg; } - set { launchErrorMsg = value; } - } + #region Constructor - #endregion + public ApplicationItem() + { - #region Events - - public delegate void FilelinkLaunchEventHandler(FilelinkItem curLink, bool mpGuiMode); - public event FilelinkLaunchEventHandler OnLaunchFilelink = null; - - // event: read new file - public delegate void RefreshInfoEventHandler(string informationMessage, int progressBarProgess); - public event RefreshInfoEventHandler OnRefreshInfo = null; - - #endregion - - #region Constructor - - public ApplicationItem() - { - - // .. init member variables ... - appID = -1; - fatherID = -1; - title = ""; - filename = ""; - arguments = ""; - windowStyle = ProcessWindowStyle.Normal; - startupDir = "%FILEDIR%"; - useShellExecute = false; - useQuotes = true; - enabled = true; - sourceType = ItemType.UNKNOWN; - sourceFile = ""; - imageFile = ""; - fileDirectory = ""; - imageDirectories = ""; - validExtensions = ""; - appPosition = 0; - importValidImagesOnly = false; + // .. init member variables ... + appID = -1; + fatherID = -1; + title = ""; + filename = ""; + arguments = ""; + windowStyle = ProcessWindowStyle.Normal; + startupDir = "%FILEDIR%"; + useShellExecute = false; + useQuotes = true; + enabled = true; + sourceType = ItemType.UNKNOWN; + sourceFile = ""; + imageFile = ""; + fileDirectory = ""; + imageDirectories = ""; + validExtensions = ""; + appPosition = 0; + importValidImagesOnly = false; platformId = 0; - waitForExit = true; - filesAreLoaded = false; - preLaunch = ""; - postLaunch = ""; + waitForExit = true; + filesAreLoaded = false; + preLaunch = ""; + postLaunch = ""; - } + } - #endregion + #endregion Constructor - protected void LaunchFilelink(FilelinkItem curLink, bool MPGUIMode) - { - /*ApplicationItem targetApp = GetAppByID(curLink.TargetAppID); - if (targetApp != null) - { - targetApp.LaunchFile(curLink, MPGUIMode); - }*/ - } + #region protected methods + protected void LaunchFilelink(FilelinkItem curLink, bool MPGUIMode) + { + /*ApplicationItem targetApp = GetAppByID(curLink.TargetAppID); + if (targetApp != null) + { + targetApp.LaunchFile(curLink, MPGUIMode); + }*/ + } - protected void SendRefreshInfo(string informationMessage, int progressBarCtr) - { - if ( OnRefreshInfo != null ) - { - OnRefreshInfo( informationMessage, progressBarCtr ); - } - } - protected int GetID = ProgramUtils.GetID; + protected void SendRefreshInfo(string informationMessage, int progressBarCtr) + { + if (OnRefreshInfo != null) + { + OnRefreshInfo(informationMessage, progressBarCtr); + } + } - public FileItem PrevFile(FileItem curFile) - { - if ( ItemList == null ) return null; - if ( ItemList.Count == 0 ) return null; - int index = this.ItemList.IndexOf( curFile ); - index = index - 1; - if ( index < 0 ) - index = ItemList.Count - 1; - return ( FileItem ) ItemList[index]; - } + protected void DoPreLaunch() + { + if (waitForExit && (preLaunch != "")) + { + LaunchCmd(preLaunch); + } + } - public FileItem NextFile(FileItem curFile) - { - if ( ItemList == null ) return null; - if ( ItemList.Count == 0 ) return null; + protected void DoPostLaunch() + { + if (waitForExit && (preLaunch != "")) + { + LaunchCmd(postLaunch); + } + } - int index = this.ItemList.IndexOf( curFile ); - index = index + 1; - if ( index > ItemList.Count - 1 ) - index = 0; - return ( FileItem ) ItemList[index]; - } + protected void LaunchCmd(string commands) + { + string results = ""; + string errors = ""; + string[] script; + string curLine; + Process p = new Process(); + StreamWriter sw; + StreamReader sr; + StreamReader err; - /// <summary> - /// look for FileItem and launch it using the found object - /// </summary> - /// <param name="guiListItem"></param> - public virtual void LaunchFile(BaseItem launchItem) - { - FileItem curFileItem = ( FileItem ) launchItem; - if ( curFileItem == null ) return; + script = commands.Split(';'); + if (script.Length > 0) + { + ProcessStartInfo psI = new ProcessStartInfo("cmd"); + psI.UseShellExecute = false; + psI.RedirectStandardInput = true; + psI.RedirectStandardOutput = true; + psI.RedirectStandardError = true; + psI.CreateNoWindow = true; + p.StartInfo = psI; - this.LaunchFile( curFileItem, true ); - } + p.Start(); + sw = p.StandardInput; + sr = p.StandardOutput; + err = p.StandardError; - public virtual void LaunchFile(FileItem fileItem, bool mpGuiMode) - { - string filename = fileItem.Filename; - if ( filename == "" ) return; + sw.AutoFlush = true; - // Launch File by item - if ( mpGuiMode ) - fileItem.UpdateLaunchInfo(); + for (int i = 0; i < script.Length; i++) + { + curLine = script[i].Trim(); + curLine = curLine.TrimStart('\n'); + if (curLine != "") + sw.WriteLine(curLine); + } + sw.Close(); - ProcessStartInfo procStart = new ProcessStartInfo(); + results += sr.ReadToEnd(); + errors += err.ReadToEnd(); - if ( this.Filename != "" ) - { // use the APPLICATION launcher and add current file information + if (errors.Trim() != "") + { + Log.Info("Application PrePost errors: {0}", errors); + } + } + } - // filename of the application - procStart.FileName = this.Filename; + #endregion protected methods - // double quotes around the filename-argument..... - if ( UseQuotes ) - filename = "\"" + fileItem.Filename + "\""; + #region Public Methods - // set the arguments: one of the arguments is the fileitem-filename - if ( this.Arguments.Contains( "%FILEnoPATHnoEXT%" ) ) - // ex. kawaks: - // winkawaks.exe alpham2 - // => filename without path and extension is necessary! - procStart.Arguments = " " + this.Arguments.Replace( "%FILEnoPATHnoEXT%", Path.GetFileNameWithoutExtension( fileItem.Filename ) ); - else if ( this.Arguments.Contains( "%FILE%" ) ) - // placeholder found => replace the placeholder by the correct filename - procStart.Arguments = " " + this.Arguments.Replace( "%FILE%", filename ); - else - // no placeholder found => default handling: add the fileitem as the last argument - procStart.Arguments = " " + this.Arguments + " " + filename; - // set WorkingDirectory - if ( this.StartupDir.Contains( "%FILEDIR%" ) ) - procStart.WorkingDirectory = this.StartupDir.Replace( "%FILEDIR%", Path.GetDirectoryName( fileItem.Filename ) ); - else - procStart.WorkingDirectory = this.StartupDir; - } - else - { - // application has no launch-file - // => try to make a correct launch using the current FILE object - if ( UseQuotes ) - { - procStart.FileName = "\"" + fileItem.Filename + "\""; - } - else - { - procStart.FileName = fileItem.Filename; - } + public virtual string CurrentFilePath() + { + return this.FileDirectory; + } - // set WorkingDirectory - if ( this.StartupDir == "" ) - procStart.WorkingDirectory = Path.GetDirectoryName( fileItem.Filename ); - else if ( this.StartupDir.Contains( "%FILEDIR%" ) ) - procStart.WorkingDirectory = this.StartupDir.Replace( "%FILEDIR%", Path.GetDirectoryName( fileItem.Filename ) ); - else - procStart.WorkingDirectory = this.StartupDir; - } + public void Assign(ApplicationItem sourceApp) + { + this.Enabled = sourceApp.Enabled; + this.ApplicationItemId = sourceApp.ApplicationItemId; + this.FatherID = sourceApp.FatherID; + this.Title = sourceApp.Title; + this.Filename = sourceApp.Filename; + this.Arguments = sourceApp.Arguments; + this.WindowStyle = sourceApp.WindowStyle; + this.StartupDir = sourceApp.StartupDir; + this.UseShellExecute = sourceApp.UseShellExecute; + this.UseQuotes = sourceApp.UseQuotes; + this.SourceType = sourceApp.SourceType; + this.Source = sourceApp.Source; + this.Imagefile = sourceApp.Imagefile; + this.FileDirectory = sourceApp.FileDirectory; + this.ImageDirectory = sourceApp.ImageDirectory; + this.ValidExtensions = sourceApp.ValidExtensions; + this.ImportValidImagesOnly = sourceApp.ImportValidImagesOnly; + this.Position = sourceApp.Position; + this.WaitForExit = sourceApp.WaitForExit; + this.PreLaunch = sourceApp.PreLaunch; + this.PostLaunch = sourceApp.PostLaunch; + this.PlatformId = sourceApp.PlatformId; - // set UseShellExecute - procStart.UseShellExecute = this.UseShellExecute; - // set WindowStyle - procStart.WindowStyle = this.WindowStyle; + } - this.LaunchErrorMsg = ""; - try - { - DoPreLaunch(); + public FileItem PrevFile(FileItem curFile) + { + if (ItemList == null) return null; + if (ItemList.Count == 0) return null; - if ( mpGuiMode ) - { - AutoPlay.StopListening(); - if ( g_Player.Playing ) - g_Player.Stop(); - } + int index = this.ItemList.IndexOf(curFile); + index = index - 1; + if (index < 0) + index = ItemList.Count - 1; + return (FileItem)ItemList[index]; + } - //proc = new Process(); - /*proc.EnableRaisingEvents = true; - proc.Exited += new EventHandler(proc_Exited); + public FileItem NextFile(FileItem curFile) + { + if (ItemList == null) return null; + if (ItemList.Count == 0) return null; - proc.StartInfo = procStart; - ProgramUtils.StartProcess(proc, this.WaitForExit); - */ - Utils.StartProcess( procStart, this.WaitForExit ); + int index = this.ItemList.IndexOf(curFile); + index = index + 1; + if (index > ItemList.Count - 1) + index = 0; + return (FileItem)ItemList[index]; + } - if ( mpGuiMode ) - { - GUIGraphicsContext.DX9Device.Reset( GUIGraphicsContext.DX9Device.PresentationParameters ); - AutoPlay.StartListening(); - } - } - catch ( Exception ex ) - { - string ErrorString = String.Format( "myPrograms: error launching program\n filename: {0}\n arguments: {1}\n WorkingDirectory: {2}\n stack: {3} {4} {5}", - procStart.FileName, - procStart.Arguments, - procStart.WorkingDirectory, - ex.Message, - ex.Source, - ex.StackTrace ); - Log.Info( ErrorString ); - this.LaunchErrorMsg = ErrorString; - } - finally - { - DoPostLaunch(); - } - } + /// <summary> + /// look for FileItem and launch it using the found object + /// </summary> + /// <param name="guiListItem"></param> + public virtual void LaunchFile(FileItem launchItem) + { + FileItem curFileItem = launchItem; + if (curFileItem == null) return; + this.LaunchFile(curFileItem, true); + } - protected void DoPreLaunch() - { - if ( waitForExit && ( preLaunch != "" ) ) - { - LaunchCmd( preLaunch ); - } - } + public virtual void LaunchFile(FileItem fileItem, bool mpGuiMode) + { + string filename = fileItem.Filename; + if (filename == "") return; - protected void DoPostLaunch() - { - if ( waitForExit && ( preLaunch != "" ) ) - { - LaunchCmd( postLaunch ); - } - } + // Launch File by item + if (mpGuiMode) + fileItem.UpdateLaunchInfo(); - public override void ItemLoad(int appID, string pathSubfolders) - { + ProcessStartInfo procStart = new ProcessStartInfo(); - try - { - ItemList.Clear(); + if (this.Filename != "") + { // use the APPLICATION launcher and add current file information - filePath = pathSubfolders; - string sqlQuery = ViewHandler.BuildQuery( appID, pathSubfolders ); + // filename of the application + procStart.FileName = this.Filename; - using (SQLiteCommand command = dbHandlerInstance.SqlLiteConn.CreateCommand()) - { - command.CommandText = sqlQuery; - using ( SQLiteDataReader dataReader = command.ExecuteReader() ) - { - while ( dataReader.Read() ) - { - if ( ViewHandler.IsFilterQuery ) - { - FilterItem curFile = (FilterItem) itemFactoryInstance.GetItem(ItemType.FILTERITEM, dataReader); - ItemList.Add( curFile ); - } - else - { - FileItem curFile = (FileItem) itemFactoryInstance.GetItem(ItemType.FILEITEM, dataReader); - ItemList.Add( curFile ); - } - } + // double quotes around the filename-argument..... + if (UseQuotes) + filename = "\"" + fileItem.Filename + "\""; - } - } - } - catch ( SQLiteException ex ) - { - Log.Info( "Filedatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace ); - } - } + // set the arguments: one of the arguments is the fileitem-filename + if (this.Arguments.Contains("%FILEnoPATHnoEXT%")) + // ex. kawaks: + // winkawaks.exe alpham2 + // => filename without path and extension is necessary! + procStart.Arguments = " " + this.Arguments.Replace("%FILEnoPATHnoEXT%", Path.GetFileNameWithoutExtension(fileItem.Filename)); + else if (this.Arguments.Contains("%FILE%")) + // placeholder found => replace the placeholder by the correct filename + procStart.Arguments = " " + this.Arguments.Replace("%FILE%", filename); + else + // no placeholder found => default handling: add the fileitem as the last argument + procStart.Arguments = " " + this.Arguments + " " + filename; - protected void LaunchCmd(string commands) - { - string results = ""; - string errors = ""; - string[] script; - string curLine; - Process p = new Process(); - StreamWriter sw; - StreamReader sr; - StreamReader err; - - script = commands.Split( ';' ); - if ( script.Length > 0 ) - { - ProcessStartInfo psI = new ProcessStartInfo( "cmd" ); - psI.UseShellExecute = false; - psI.RedirectStandardInput = true; - psI.RedirectStandardOutput = true; - psI.RedirectStandardError = true; - psI.CreateNoWindow = true; - p.StartInfo = psI; - - p.Start(); - sw = p.StandardInput; - sr = p.StandardOutput; - err = p.StandardError; - - sw.AutoFlush = true; - - for ( int i = 0; i < script.Length; i++ ) - { - curLine = script[i].Trim(); - curLine = curLine.TrimStart( '\n' ); - if ( curLine != "" ) - sw.WriteLine( curLine ); - } - sw.Close(); - - results += sr.ReadToEnd(); - errors += err.ReadToEnd(); - - if ( errors.Trim() != "" ) - { - Log.Info( "Application PrePost errors: {0}", errors ); - } - } - } - - public virtual string DefaultFilepath() - { - return ""; // override this if the appitem can have subfolders - } - - public virtual int DisplayFiles(string filePath, GUIFacadeControl facadeView) - { - int totalItems = 0; - - totalItems = totalItems + DisplayItemList( filePath, this.ItemList, facadeView ); - - return totalItems; - } - - - #region moved from BaseItem - - public int DisplayItemList(string filePath, List<BaseItem> dbItems, GUIFacadeControl facadeView) - { - int totalItems = 0; - - foreach (BaseItem baseItem in dbItems) + // set WorkingDirectory + if (this.StartupDir.Contains("%FILEDIR%")) + procStart.WorkingDirectory = this.StartupDir.Replace("%FILEDIR%", Path.GetDirectoryName(fileItem.Filename)); + else + procStart.WorkingDirectory = this.StartupDir; + } + else { - totalItems = totalItems + 1; - - if (baseItem is FileItem) + // application has no launch-file + // => try to make a correct launch using the current FILE object + if (UseQuotes) { - FileItem curFile = baseItem as FileItem; - GUIListItem gli = new GUIListItem(curFile.Title); - - gli.MusicTag = curFile; - // gli.IsFolder = curFile.IsFolder; - gli.OnRetrieveArt += new MediaPortal.GUI.Library.GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt); - gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(gli); + procStart.FileName = "\"" + fileItem.Filename + "\""; } - if (baseItem is FilterItem) + else { - FilterItem curFile = baseItem as FilterItem; - GUIListItem gli = new GUIListItem(curFile.Title); - gli.MusicTag = curFile; - //gli.IsFolder = false; - gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(gli); + procStart.FileName = fileItem.Filename; } + + // set WorkingDirectory + if (this.StartupDir == "") + procStart.WorkingDirectory = Path.GetDirectoryName(fileItem.Filename); + else if (this.StartupDir.Contains("%FILEDIR%")) + procStart.WorkingDirectory = this.StartupDir.Replace("%FILEDIR%", Path.GetDirectoryName(fileItem.Filename)); + else + procStart.WorkingDirectory = this.StartupDir; } - return totalItems; - } - protected void OnRetrieveCoverArt(GUIListItem guiListItem) - { - if (guiListItem.MusicTag == null) return; - FileItem curFileItem = (FileItem)guiListItem.MusicTag; - if (curFileItem == null) return; + // set UseShellExecute + procStart.UseShellExecute = this.UseShellExecute; + // set WindowStyle + procStart.WindowStyle = this.WindowStyle; - string imgFile = String.Empty; + this.LaunchErrorMsg = ""; + try + { + DoPreLaunch(); - if (ProgramUtils.UseThumbsDir()) - imgFile = ProgramUtils.GetFileImage(this,curFileItem); - else - imgFile = curFileItem.Imagefile; + if (mpGuiMode) + { + AutoPlay.StopListening(); + if (g_Player.Playing) + g_Player.Stop(); + } - if (File.Exists(imgFile)) + //proc = new Process(); + /*proc.EnableRaisingEvents = true; + proc.Exited += new EventHandler(proc_Exited); + + proc.StartInfo = procStart; + ProgramUtils.StartProcess(proc, this.WaitForExit); + */ + Utils.StartProcess(procStart, this.WaitForExit); + + if (mpGuiMode) + { + GUIGraphicsContext.DX9Device.Reset(GUIGraphicsContext.DX9Device.PresentationParameters); + AutoPlay.StartListening(); + } + } + catch (Exception ex) { - guiListItem.ThumbnailImage = imgFile; - guiListItem.IconImageBig = imgFile; - guiListItem.IconImage = imgFile; + string ErrorString = String.Format("myPrograms: error launching program\n filename: {0}\n arguments: {1}\n WorkingDirectory: {2}\n stack: {3} {4} {5}", + procStart.FileName, + procStart.Arguments, + procStart.WorkingDirectory, + ex.Message, + ex.Source, + ex.StackTrace); + Log.Info(ErrorString); + this.LaunchErrorMsg = ErrorString; } - else + finally { - guiListItem.ThumbnailImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - guiListItem.IconImageBig = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - guiListItem.IconImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderNF.png"; + DoPostLaunch(); } } - #endregion + public virtual string DefaultFilepath() + { + return ""; // override this if the appitem can have subfolders + } + public virtual bool FileEditorAllowed() + { + return true; // otherwise, override this in child class + } - public override void OnClick(BaseItem baseItem, GUIPrograms guiPrograms) - { - ApplicationItem candidate = ( ApplicationItem ) baseItem; - guiPrograms.SaveItemIndex( guiPrograms.GetSelectedItemNo().ToString(), guiPrograms.lastApp, lastFilepath ); - guiPrograms.lastApp = candidate; - guiPrograms.mapSettings.LastAppID = guiPrograms.lastApp.ApplicationItemId; - guiPrograms.prevFilepath = guiPrograms.lastApp.DefaultFilepath(); - guiPrograms.ViewHandler.CurrentLevel = 0; - guiPrograms.lastApp.ViewHandler = guiPrograms.ViewHandler; - } + public virtual bool FileAddAllowed() + { + return true; // otherwise, override this in child class + } - /* protected int DisplayArrayList(string filePath, List<object> dbItems, GUIFacadeControl facadeView) - { - int totalItems = 0; - //foreach (FileItem currentFileItem in dbItems) - foreach (object obj in dbItems) - { - totalItems = totalItems + 1; - if (obj is FileItem) - { - FileItem curFile = obj as FileItem; - GUIListItem gli = new GUIListItem(curFile.Title); + public virtual bool FilesCanBeFavourites() + { + return true; // otherwise, override this in child class + } - gli.MusicTag = curFile; - gli.IsFolder = curFile.IsFolder; - gli.OnRetrieveArt += new MediaPortal.GUI.Library.GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt); - gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(gli); - } - } - return totalItems; - } - */ + public virtual bool FileBrowseAllowed() + { + // set this to true, if SUBDIRECTORIES are allowed + // (example: possible for DIRECTORY-CACHE) + return false; // otherwise, override this in child class + } - public virtual bool FileEditorAllowed() - { - return true; // otherwise, override this in child class - } + public virtual bool SubItemsAllowed() + { + return false; + } - public virtual bool FileAddAllowed() - { - return true; // otherwise, override this in child class - } + public virtual bool ProfileLoadingAllowed() + { + return false; + } - public virtual bool FilesCanBeFavourites() - { - return true; // otherwise, override this in child class - } + public virtual void Refresh(bool mpGuiMode) + { + // descendant classes do that! + } - public virtual bool FileBrowseAllowed() - { - // set this to true, if SUBDIRECTORIES are allowed - // (example: possible for DIRECTORY-CACHE) - return false; // otherwise, override this in child class - } + #endregion Public Methods - public virtual bool SubItemsAllowed() - { - return false; - } - public virtual bool ProfileLoadingAllowed() - { - return false; - } - public virtual void Refresh(bool mpGuiMode) - { - // descendant classes do that! - } + #region Database stuff - #region Database stuff + /// <summary> + /// get an unused SQL application KEY-number + /// </summary> + private int GetNewAppID() + { + int result = 0; + // won't work in multiuser environment :) + string sqlStmt = "SELECT MAX(applicationId) FROM tblApplicationItem"; + object o = dbHandlerInstance.ExecuteStmtScalar(sqlStmt); + if (o.ToString() != "") + { + result = Convert.ToInt32(o); + } + return result + 1; + } - /// <summary> - /// get an unused SQL application KEY-number - /// </summary> - private int GetNewAppID() - { - int result = 0; - // won't work in multiuser environment :) - string sqlStmt = "SELECT MAX(applicationId) FROM tblApplicationItem"; - object o = dbHandlerInstance.ExecuteStmtScalar( sqlStmt ); - if ( o.ToString() != "" ) - { - result = Convert.ToInt32( o ); - } - return result + 1; - } - + private void Insert() + { + SQLiteParameter[] parameterArray = new SQLiteParameter[23]; + ApplicationItemId = GetNewAppID(); // important to avoid subsequent inserts! + //params for question + values + parameterArray[0] = dbHandlerInstance.GetParameter<int>(ApplicationItemId, "@applicationItemId", DbType.Int32); + parameterArray[1] = dbHandlerInstance.GetParameter<int>(FatherID, "@fatherNodeId", DbType.Int32); + parameterArray[2] = dbHandlerInstance.GetParameter<string>(Title, "@title", DbType.String); + parameterArray[3] = dbHandlerInstance.GetParameter<string>(Filename, "@filename", DbType.String); + parameterArray[4] = dbHandlerInstance.GetParameter<string>(Arguments, "@arguments", DbType.String); + parameterArray[5] = dbHandlerInstance.GetParameter<string>(ProgramUtils.WindowStyleToStr(WindowStyle), "@windowStyle", DbType.String); + parameterArray[6] = dbHandlerInstance.GetParameter<string>(StartupDir, "@startupDir", DbType.String); + parameterArray[7] = dbHandlerInstance.GetParameter<bool>(UseShellExecute, "@useShellExecute", DbType.Boolean); + parameterArray[8] = dbHandlerInstance.GetParameter<bool>(UseQuotes, "@useQuotes", DbType.Boolean); + parameterArray[9] = dbHandlerInstance.GetParameter<string>(ProgramUtils.ApplicationTypeToString(SourceType), "@applicationItemType", DbType.String); + parameterArray[10] = dbHandlerInstance.GetParameter<string>(Source, "@source", DbType.String); + parameterArray[11] = dbHandlerInstance.GetParameter<string>(imageFile, "@imageFile", DbType.String); + parameterArray[12] = dbHandlerInstance.GetParameter<string>(FileDire... [truncated message content] |