From: <nor...@us...> - 2007-07-22 19:06:57
|
Revision: 752 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=752&view=rev Author: northern_sky Date: 2007-07-22 12:06:56 -0700 (Sun, 22 Jul 2007) Log Message: ----------- Added Paths: ----------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemDirectoryCache.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemFactory.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGameBase.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGrouper.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemList.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemMame.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/BaseItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FileItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FileItemInfo.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FilelinkItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/FilterItem.cs Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItem.cs 2007-07-22 19:06:56 UTC (rev 752) @@ -0,0 +1,1149 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Xml; +using SQLite.NET; + +using MediaPortal.Configuration; +using MediaPortal.GUI.Library; +using MediaPortal.Player; +using MediaPortal.Ripper; +using MediaPortal.Util; + +using GUIPrograms; +using GUIPrograms.Database; +using GUIPrograms.Items; + + +namespace GUIPrograms.Items +{ + public class ApplicationItem : BaseItem + { + #region Variables + + + + int appID; + int fatherID; + string title; + string filename; + + string arguments; + ProcessWindowStyle windowStyle; + string startupDir; + bool useQuotes; + bool useShellExecute; + bool waitForExit; + string preLaunch; + string postLaunch; + + bool enabled; + int appPosition; + + string currentView = ""; + + public bool filesAreLoaded = false; // load on demand.... + // protected FileItemList fileList = null; + + public bool linksAreLoaded = false; // load on demand.... + + + + bool importMamePlaychoice10 = false; + bool importMameMahjong = false; + bool refreshGUIAllowed = false; + + + + + + // more variables, maybe need some renaming or anything else + Process proc; + 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; + + string systemDefault; + + string launchErrorMsg; + // two magic image-slideshow counters + int thumbIndex = 0; + int thumbFolderIndex = -1; + + protected string lastFilepath = ""; // cached path + + //private DatabaseSorter dbPc = new DatabaseSorter(); + //private ProgramSort dbPc = new ProgramSort(ProgramSort.SortMethod.Name, true); + + #endregion + + #region Properties + // Helper Routines + + public SQLiteClient db + { + get { return sqlDB; } + } + + public int AppID + { + 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 + { + if (File.Exists(imageFile)) + return imageFile; + else + return MediaPortal.Util.Utils.GetCoverArtName( + Config.GetSubFolder(Config.Dir.Thumbs, @"MyProgramsAlt"), + this.Title + ); + } + set { imageFile = 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 Enabled + { + get { return enabled; } + set { enabled = value; } + } + + public virtual bool RefreshGUIAllowed + { + get { return refreshGUIAllowed; } + set { refreshGUIAllowed = value; } + } + + public int Position + { + get { return appPosition; } + set { appPosition = value; } + } + + + public string CurrentView + { + get { return currentView; } + set { currentView = value; } + } + + public bool ImportMamePlaychoice10 + { + get { return importMamePlaychoice10; } + set { importMamePlaychoice10 = value; } + } + public bool ImportMameMahjong + { + get { return importMameMahjong; } + set { importMameMahjong = 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 string SystemDefault + { + get { return systemDefault; } + set { systemDefault = value; } + } + public string LaunchErrorMsg + { + get { return launchErrorMsg; } + set { launchErrorMsg = value; } + } + + #endregion + + #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(SQLiteClient initSqlDb) : base(initSqlDb) + { + + // .. 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; + systemDefault = ""; + waitForExit = true; + filesAreLoaded = false; + preLaunch = ""; + postLaunch = ""; + + } + + #endregion + + + + + protected void SendRefreshInfo(string informationMessage, int progressBarCtr) + { + if (OnRefreshInfo != null) + { + OnRefreshInfo(informationMessage, progressBarCtr); + } + } + + protected int GetID = ProgramUtils.GetID; + + + + + 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]; + } + + public FileItem NextFile(FileItem curFile) + { + if (ItemList == null) return null; + if (ItemList.Count == 0) return null; + + int index = this.ItemList.IndexOf(curFile); + index = index + 1; + if (index > ItemList.Count - 1) + index = 0; + return (FileItem)ItemList[index]; + } + + /// <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; + + this.LaunchFile(curFileItem, true); + } + + public virtual void LaunchFile(FileItem curFileItem, bool mpGuiMode) + { + string curFilename = curFileItem.Filename; + if (curFilename == "") return; + + // Launch File by item + if (mpGuiMode) + curFileItem.UpdateLaunchInfo(); + + ProcessStartInfo procStart = new ProcessStartInfo(); + + if (this.Filename != "") + { // use the APPLICATION launcher and add current file information + + // filename of the application + procStart.FileName = this.Filename; + + // double quotes around the filename-argument..... + if (UseQuotes) + curFilename = "\"" + curFileItem.Filename + "\""; + + // 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(curFileItem.Filename)); + else if (this.Arguments.Contains("%FILE%")) + // placeholder found => replace the placeholder by the correct filename + procStart.Arguments = " " + this.Arguments.Replace("%FILE%", curFilename); + else + // no placeholder found => default handling: add the fileitem as the last argument + procStart.Arguments = " " + this.Arguments + " " + curFilename; + + // set WorkingDirectory + if (this.StartupDir.Contains("%FILEDIR%")) + procStart.WorkingDirectory = this.StartupDir.Replace("%FILEDIR%", Path.GetDirectoryName(curFileItem.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 = "\"" + curFileItem.Filename + "\""; + } + else + { + procStart.FileName = curFileItem.Filename; + } + + // set WorkingDirectory + if (this.StartupDir == "") + procStart.WorkingDirectory = Path.GetDirectoryName(curFileItem.Filename); + else if (this.StartupDir.Contains("%FILEDIR%")) + procStart.WorkingDirectory = this.StartupDir.Replace("%FILEDIR%", Path.GetDirectoryName(curFileItem.Filename)); + else + procStart.WorkingDirectory = this.StartupDir; + } + + // set UseShellExecute + procStart.UseShellExecute = this.UseShellExecute; + // set WindowStyle + procStart.WindowStyle = this.WindowStyle; + + this.LaunchErrorMsg = ""; + try + { + DoPreLaunch(); + + if (mpGuiMode) + { + AutoPlay.StopListening(); + if (g_Player.Playing) + g_Player.Stop(); + } + + //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) + { + 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(); + } + } + + protected virtual void LaunchFilelink(FilelinkItem curLink, bool MPGUIMode) + { + this.OnLaunchFilelink(curLink, MPGUIMode); + } + + void proc_Exited(object sender, EventArgs e) + { + + if (proc != null) + { + proc.Dispose(); + proc = null; + } + } + + protected void DoPreLaunch() + { + if (waitForExit && (preLaunch != "")) + { + LaunchCmd(preLaunch); + } + } + + protected void DoPostLaunch() + { + if (waitForExit && (preLaunch != "")) + { + LaunchCmd(postLaunch); + } + } + + 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; + if (filePath != lastFilepath) + { + ItemLoad(AppID, filePath); + //Filelinks.Load(AppID, filePath); + } + totalItems = totalItems + DisplayItemList(filePath, this.ItemList, facadeView); + // totalItems = totalItems + DisplayArrayList(filePath, this.Filelinks, facadeView); + lastFilepath = filePath; + return totalItems; + } + + 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.AppID; + guiPrograms.lastFilepath = guiPrograms.lastApp.DefaultFilepath(); + guiPrograms.ViewHandler.CurrentLevel = 0; + guiPrograms.lastApp.ViewHandler = guiPrograms.ViewHandler; + } + + 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); + + 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 FileEditorAllowed() + { + return true; // otherwise, override this in child class + } + + public virtual bool FileAddAllowed() + { + return true; // otherwise, override this in child class + } + + public virtual bool FilesCanBeFavourites() + { + return true; // otherwise, override this in child class + } + + 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 SubItemsAllowed() + { + return false; + } + + public virtual bool ProfileLoadingAllowed() + { + return false; + } + + public virtual void Refresh(bool mpGuiMode) + { + // descendant classes do that! + } + + #region Database stuff + + /// <summary> + /// get an unused SQL application KEY-number + /// </summary> + private int GetNewAppID() + { + if (sqlDB == null) return -1; + + // won't work in multiuser environment :) + SQLiteResultSet results; + int res = 0; + results = sqlDB.Execute("SELECT MAX(applicationId) FROM tblApplicationItem"); + SQLiteResultSet.Row arr = results.Rows[0]; + if (arr.fields[0] != null) + { + if (arr.fields[0] != "") + { + res = Int32.Parse(arr.fields[0]); + } + } + return res + 1; + } + + private void Insert() + { + if (sqlDB == null) return; + + string sql = ""; + + try + { + AppID = GetNewAppID(); // important to avoid subsequent inserts! + sql = String.Format(@" + INSERT INTO + tblApplicationItem + ( + applicationId, + fatherNodeId, + title, + filename, + arguments, + windowstyle, + startupdir, + useShellExecute, + useQuotes, + applicationItemType, + source, + imagefile, + filedirectory, + imagedirectory, + validExtensions, + importValidImagesOnly, + iposition, + enabled, + refreshGUIAllowed, + systemDefault, + waitForExit, + preLaunch, + postLaunch + ) + VALUES + ( + '"+ AppID + @"', + '"+ FatherID + @"', + '"+ ProgramUtils.Encode(Title) +@"', + '"+ ProgramUtils.Encode(Filename) +@"', + '"+ ProgramUtils.Encode(Arguments) + @"', + '"+ ProgramUtils.WindowStyleToStr(WindowStyle) +@"', + '"+ ProgramUtils.Encode(StartupDir) +@"', + '"+ ProgramUtils.BooleanToStr(UseShellExecute) +@"', + '"+ ProgramUtils.BooleanToStr(UseQuotes) +@"', + '"+ ProgramUtils.ApplicationTypeToString(SourceType) +@"', + '"+ ProgramUtils.Encode(Source) +@"', + '"+ ProgramUtils.Encode(Imagefile) +@"', + '"+ ProgramUtils.Encode(FileDirectory) +@"', + '"+ ProgramUtils.Encode(ImageDirectory)+@"', + '"+ ProgramUtils.Encode(ValidExtensions)+@"', + '"+ ProgramUtils.BooleanToStr(importValidImagesOnly)+@"', + '"+ Position+@"', + '"+ ProgramUtils.BooleanToStr(Enabled)+@"', + '" + ProgramUtils.BooleanToStr(RefreshGUIAllowed)+@"', + '"+ ProgramUtils.Encode(SystemDefault)+@"', + '"+ ProgramUtils.BooleanToStr(WaitForExit) +@"', + '"+ ProgramUtils.Encode(PreLaunch)+@"', + '"+ ProgramUtils.Encode(PostLaunch)+@"' + )" + + ); + sqlDB.Execute(sql); + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + } + + private void Update() + { + if (sqlDB == null) return; + if (AppID == -1) return; + + string sql = ""; + + try + { + sql = String.Format( + @"UPDATE + tblApplicationItem SET + + title = '" + ProgramUtils.Encode(Title) + @"', + filename = '" + ProgramUtils.Encode(Filename) + @"', + arguments = '" + ProgramUtils.Encode(Arguments) + @"', + windowstyle = '" + ProgramUtils.WindowStyleToStr(WindowStyle) + @"', + startupdir = '" + ProgramUtils.Encode(StartupDir) + @"', + useShellExecute = '" + ProgramUtils.BooleanToStr(UseShellExecute) + @"', + useQuotes = '" + ProgramUtils.BooleanToStr(UseQuotes) + @"', + applicationItemType = '" + ProgramUtils.ApplicationTypeToString(SourceType) + @"', + source = '" + ProgramUtils.Encode(Source) + @"', + imagefile = '" + ProgramUtils.Encode(Imagefile) + @"', + filedirectory = '" + ProgramUtils.Encode(FileDirectory) + @"', + imagedirectory = '" + ProgramUtils.Encode(ImageDirectory) + @"', + validExtensions = '" + ProgramUtils.Encode(ValidExtensions) + @"', + importValidImagesOnly = '" + ProgramUtils.BooleanToStr(importValidImagesOnly) + @"', + iposition = " + Position + @", + enabled = '" + ProgramUtils.BooleanToStr(Enabled) + @"', + fatherNodeId = '" + FatherID + @"', + refreshGUIAllowed = '" + ProgramUtils.BooleanToStr(RefreshGUIAllowed) +@"', + systemDefault = '" + ProgramUtils.Encode(SystemDefault) + @"', + waitForExit = '" + ProgramUtils.BooleanToStr(WaitForExit) + @"', + preLaunch = '" + ProgramUtils.Encode(PreLaunch) + @"', + postLaunch = '" + ProgramUtils.Encode(PostLaunch) + @"' + + WHERE applicationId = " + AppID); + sqlDB.Execute(sql); + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + Log.Info("sql \n{0}", sql); + } + } + + public void Delete() + { + if (sqlDB == null) return; + if (AppID == -1) return; + + try + { + DeleteFiles(); + DeleteFileLinks(); + sqlDB.Execute(String.Format("delete from tblApplicationItem where applicationId = {0}", AppID)); + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + } + + + protected void DeleteFiles() + { + if (sqlDB == null) return; + if (AppID == -1) return; + + try + { + sqlDB.Execute(String.Format("delete from tblFileItem where applicationId = {0}", AppID)); + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + } + + protected void DeleteFileLinks() + { + if (sqlDB == null) return; + if (AppID == -1) return; + + try + { + sqlDB.Execute(String.Format("delete from tblFilterItem where applicationId = {0} or grouperappid = {0}", AppID)); + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + } + + public virtual void LoadFiles() + { + //linksAreLoaded = true; + if (sqlDB == null) return; + + lastFilepath = ""; + ItemLoad(AppID, ""); + filesAreLoaded = true; + } + + + + + + public void InsertOrUpdateSettings() + { + if (appID == -1) + Insert(); + else + Update(); + } + + #endregion + + protected virtual void FixFileLinks() + { + // after a import the appitem has completely new + // fileitems (new ids) and LINKS stored in filteritems + // are out of sync... fix this here! + + // query with data to fix + string sqlSelectDataToFix = String.Format("select fi.applicationId, fi.fileid as oldfileid, f.fileid as newfileid, fi.filename as filename from tblFilterItem fi, tblFileItem f where fi.applicationId = f.applicationId and fi.filename = f.filename and fi.applicationId = {0}", AppID); + + // update command to fix one single link + string sqlFixOneLink = "update tblFilterItem set fileID = {0}, tag = 0 where applicationId = {1} and filename = '{2}'"; + + SQLiteResultSet rows2fix; + + + try + { + // 1) initialize TAG + sqlDB.Execute(String.Format("update tblFilterItem set tag = 1234 where applicationId = {0}", AppID)); + + // 2) fix all fileids of the newly imported files + rows2fix = sqlDB.Execute(sqlSelectDataToFix); + int newFileID; + string filenameToFix; + if (rows2fix.Rows.Count == 0) return; + for (int row = 0; row < rows2fix.Rows.Count; row++) + { + newFileID = ProgramUtils.GetIntDef(rows2fix, row, "newfileid", -1); + filenameToFix = ProgramUtils.Get(rows2fix, row, "filename"); + sqlDB.Execute(String.Format(sqlFixOneLink, newFileID, AppID, ProgramUtils.Encode(filenameToFix))); + } + + // 3) delete untouched links ( they were not imported anymore ) + sqlDB.Execute(String.Format("delete from tblFilterItem where applicationId = {0} and tag = 1234", AppID)); + + } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception (Application.FixFileLinks) err:{0} stack:{1}", ex.Message, ex.StackTrace); + } + + } + + public virtual string CurrentFilePath() + { + return this.FileDirectory; + } + + public void Assign(ApplicationItem sourceApp) + { + this.Enabled = sourceApp.Enabled; + this.AppID = sourceApp.AppID; + 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.SystemDefault = sourceApp.SystemDefault; + + } + + #region imagedirectory stuff + + // get next imagedirectory that holds at least one image for a fileitem + // * m_pFile: the file we're looking images for + private void GetNextThumbFolderIndex(FileItem fileItem) + { + if (fileItem == null) return; + bool foundThumb = false; + while (!foundThumb) + { + thumbFolderIndex++; + if (thumbFolderIndex >= imageDirs.Length) + { + thumbFolderIndex = -1; + foundThumb = true; + } + else + { + string candFolder = imageDirs[thumbFolderIndex]; + string candThumb = candFolder + "\\" + fileItem.ExtractImageFileNoPath(); + if (candThumb.ToLower() != fileItem.Imagefile.ToLower()) + { + foundThumb = (System.IO.File.Exists(candThumb)); + } + else + { + // skip the initial directory, in case it's reentered as a search directory! + foundThumb = false; + } + } + } + } + + public virtual string GetCurThumb(GUIListItem item) + { + if (item.MusicTag == null) return ""; + + if (item.MusicTag is FileItem) + { + FileItem curFile = item.MusicTag as FileItem; + + if (DatabaseHandler.useMPsThumbDirectory) + return GetCurThumbFromThumbsDir(curFile); + else + return GetCurThumb(curFile); + } + else if (item.MusicTag is ApplicationItem) + { + ApplicationItem curApp = item.MusicTag as ApplicationItem; + + return curApp.Imagefile; + } + else return ""; + } + + public string GetCurThumb(FileItem fileItem) + { + string curThumb = ""; + + if (thumbFolderIndex == -1) + { + curThumb = fileItem.Imagefile; + } + else + { + string curFolder = imageDirs[thumbFolderIndex]; + curThumb = curFolder + "\\" + fileItem.ExtractImageFileNoPath(); + } + + if (thumbIndex > 0) + { + // try to find another thumb.... + // use the myGames convention: + // every thumb has the postfix "_1", "_2", etc with the same file extension + string curExtension = fileItem.ExtractImageExtension(); + if (curThumb != "") + { + string cand = curThumb.Replace(curExtension, "_" + thumbIndex.ToString() + curExtension); + if (System.IO.File.Exists(cand)) + { + // found another thumb => override the filename! + curThumb = cand; + } + else + { + thumbIndex = 0; // restart at the first thumb! + GetNextThumbFolderIndex(fileItem); + } + } + } + + return curThumb; + } + + public string GetCurThumbFromThumbsDir(FileItem fileItem) + { + string curThumb = MediaPortal.Util.Utils.GetCoverArtName( + Config.GetSubFolder(Config.Dir.Thumbs, @"MyProgramsAlt\" + this.Title), + Path.GetFileNameWithoutExtension(fileItem.Filename) + ); + + if (File.Exists(curThumb)) + if (thumbIndex > 0) + { + // try to find another thumb.... + // use the myGames convention: + // every thumb has the postfix "_1", "_2", etc with the same file extension + string cand = MediaPortal.Util.Utils.GetCoverArtName( + Config.GetSubFolder(Config.Dir.Thumbs, @"MyProgramsAlt\" + this.Title), + Path.GetFileNameWithoutExtension(fileItem.Filename) + "_" + thumbIndex.ToString() + ); + + if (File.Exists(cand)) + curThumb = cand; + else + { + // restart at the first thumb! + thumbIndex = 0; + } + } + + return curThumb; + } + + public void ResetThumbs() + { + thumbIndex = 0; + thumbFolderIndex = -1; + } + + public void NextThumb() + { + thumbIndex++; + } + + #endregion + + public void LoadFromXmlProfile(XmlNode node) + { + + XmlNode titleNode = node.SelectSingleNode("title"); + if (titleNode != null) + { + this.Title = titleNode.InnerText; + } + + XmlNode launchingAppNode = node.SelectSingleNode("launchingApplication"); + if (launchingAppNode != null) + { + this.Filename = launchingAppNode.InnerText; + } + + XmlNode useShellExecuteNode = node.SelectSingleNode("useShellExecute"); + if (useShellExecuteNode != null) + { + this.UseShellExecute = ProgramUtils.StrToBoolean(useShellExecuteNode.InnerText); + } + + XmlNode argumentsNode = node.SelectSingleNode("arguments"); + if (argumentsNode != null) + { + this.Arguments = argumentsNode.InnerText; + } + + XmlNode windowStyleNode = node.SelectSingleNode("windowStyle"); + if (windowStyleNode != null) + { + this.WindowStyle = ProgramUtils.StringToWindowStyle(windowStyleNode.InnerText); + } + + XmlNode startupDirNode = node.SelectSingleNode("startupDir"); + if (startupDirNode != null) + { + this.StartupDir = startupDirNode.InnerText; + } + + XmlNode useQuotesNode = node.SelectSingleNode("useQuotes"); + if (useQuotesNode != null) + { + this.UseQuotes = ProgramUtils.StrToBoolean(useQuotesNode.InnerText); + } + + XmlNode fileExtensioneNode = node.SelectSingleNode("fileextensions"); + if (fileExtensioneNode != null) + { + this.ValidExtensions = fileExtensioneNode.InnerText; + } + } + } +} \ No newline at end of file Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemDirectoryCache.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemDirectoryCache.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemDirectoryCache.cs 2007-07-22 19:06:56 UTC (rev 752) @@ -0,0 +1,315 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; +using SQLite.NET; + +using MediaPortal.Dialogs; +using MediaPortal.GUI.Library; +using MediaPortal.Util; + +using GUIPrograms; +using GUIPrograms.Database; +using GUIPrograms.Items; + +namespace GUIPrograms.Items +{ + /// <summary> + /// Summary description for ApplicationItemDirectoryCache. + /// </summary> + public class ApplicationItemDirectoryCache : ApplicationItem + { + GUIDialogProgress progressDialog = null; + + public ApplicationItemDirectoryCache(SQLiteClient initSqlDB) : base(initSqlDB) { } + + private void ShowProgressDialog() + { + progressDialog = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS); + progressDialog.ShowWaitCursor = true; + progressDialog.SetHeading(GUILocalizeStrings.Get(13014)); + progressDialog.SetLine(0, GUILocalizeStrings.Get(13014)); + progressDialog.SetLine(1, ""); + progressDialog.SetLine(2, ""); + progressDialog.StartModal(GetID); + progressDialog.Progress(); + } + + private void CloseProgressDialog() + { + progressDialog.Close(); + } + + private string GetThumbsFile(FileInfo file, string fileTitle) + { + string thumbFolder = ""; + + if (imageDirs.Length > 0) + { + string mainImgFolder = ""; + + foreach (string imgFolder in imageDirs) + { + if (System.IO.Directory.Exists(imgFolder)) + { + mainImgFolder = imgFolder; + } + } + + if ("" != mainImgFolder) + { + string curDir = mainImgFolder + "\\"; + string filenameNoExtension = mainImgFolder + "\\" + file.Name; + filenameNoExtension = Path.ChangeExtension(filenameNoExtension, null); + filenameNoExtension = Path.GetFileNameWithoutExtension(filenameNoExtension); + + string[] exactMatchesJPG = Directory.GetFiles(curDir, filenameNoExtension + ".jpg"); + string[] exactMatchesGIF = Directory.GetFiles(curDir, filenameNoExtension + ".gif"); + string[] exactMatchesPNG = Directory.GetFiles(curDir, filenameNoExtension + ".png"); + if (exactMatchesJPG.Length > 0) + { + thumbFolder = exactMatchesJPG[0]; + } + else if (exactMatchesGIF.Length > 0) + { + thumbFolder = exactMatchesGIF[0]; + } + else if (exactMatchesPNG.Length > 0) + { + thumbFolder = exactMatchesPNG[0]; + } + else + { + string[] almostexactMatchesJPG = Directory.GetFiles(curDir, filenameNoExtension + "*.jpg"); + string[] almostexactMatchesGIF = Directory.GetFiles(curDir, filenameNoExtension + "*.gif"); + string[] almostexactMatchesPNG = Directory.GetFiles(curDir, filenameNoExtension + "*.png"); + if (almostexactMatchesJPG.Length > 0) + { + thumbFolder = almostexactMatchesJPG[0]; + } + else if (almostexactMatchesGIF.Length > 0) + { + thumbFolder = almostexactMatchesGIF[0]; + } + else if (almostexactMatchesPNG.Length > 0) + { + thumbFolder = almostexactMatchesPNG[0]; + } + else + { + // no exact match found! Redo with near matches! + string[] nearMatchesJPG = Directory.GetFiles(curDir, fileTitle + "*.jpg"); + string[] nearMatchesGIF = Directory.GetFiles(curDir, fileTitle + "*.gif"); + string[] nearMatchesPNG = Directory.GetFiles(curDir, fileTitle + "*.png"); + if (nearMatchesJPG.Length > 0) + { + thumbFolder = nearMatchesJPG[0]; + } + else if (nearMatchesGIF.Length > 0) + { + thumbFolder = nearMatchesGIF[0]; + } + else if (nearMatchesPNG.Length > 0) + { + thumbFolder = nearMatchesPNG[0]; + } + } + } + } + } + return thumbFolder; + } + + + + private void ImportFileItem(FileInfo fileInfo) + { + FileItem curFile = new FileItem(sqlDB); + curFile.FileID = -1; // to force an INSERT statement when writing the item + curFile.AppID = this.AppID; + curFile.Title = Path.GetFileNameWithoutExtension(fileInfo.Name); + curFile.Filename = fileInfo.FullName; + + curFile.Imagefile = GetThumbsFile(fileInfo, curFile.Title); + + // not imported properties => set default values + curFile.LastTimeLaunched = DateTime.MinValue; + curFile.LaunchCount = 0; + curFile.Write(); + } + + private void UpdateProgressDialog(FileInfo fileInfo ,bool mpGuiMode) + { + if (mpGuiMode) + { + progressDialog.SetLine(2, String.Format("{0} {1}", GUILocalizeStrings.Get(13005), fileInfo.Name)); // "last imported file {0}" + progressDialog.Progress(); + } + SendRefreshInfo(String.Format("{0} {1}", GUILocalizeStrings.Get(13005), fileInfo.Name), 0); + } + + private void DeleteOrphaned() + { + string TheFileName; + ItemLoad(AppID, ""); + foreach (FileItem DBfile in ItemList) + { + + TheFileName = DBfile.Filename; + + if (!DBfile.IsFolder) + { + if (!File.Exists(TheFileName)) { DBfile.Delete(); } + } + else + { + if (!Directory.Exists(TheFileName)) { DBfile.Delete(); } + + } + + } + } + + private void ImportFile(string dirPath,bool mpGuiMode) + { + + FileInfo fileInDir = null; + if (Directory.Exists(dirPath)) + { + DirectoryInfo directoryInfo = new DirectoryInfo(dirPath); + FileSystemInfo[] allUnderLyingFiles = directoryInfo.GetFileSystemInfos(); + + for (int i = 0; i < allUnderLyingFiles.Length; i++) + { + if (allUnderLyingFiles[i] is FileInfo) + { + Boolean FileExists = false; + + fileInDir = (FileInfo)allUnderLyingFiles[i]; + + foreach (FileItem DBfile in ItemList) + { + if (DBfile.Filename == fileInDir.FullName) + { + FileExists = true; + break;//ugly + } + } + if (!FileExists) + { + ImportFileItem(fileInDir); + UpdateProgressDialog(fileInDir, mpGuiMode); + } + }//if dir found,, recurse + else if (allUnderLyingFiles[i] is DirectoryInfo) + { + DirectoryInfo directory = (DirectoryInfo)allUnderLyingFiles[i]; + ImportFile(directory.FullName, mpGuiMode); + } + } + } + } + private void ImportDirectory(string[] fileDirPaths, bool mpGuiMode) + { + //get all maindirs + foreach (string dirPath in fileDirPaths) + { + ImportFile(dirPath,mpGuiMode); + } + } + + private void DoDirCacheImport(bool mpGuiMode) + { + if (sqlDB == null) + return; + if (this.AppID < 0) + return; + if (this.SourceType != ItemType.DIRCACHE) + return; + if (mpGuiMode) + { + ShowProgressDialog(); + } + try + { + ValidExtensions = ValidExtensions.Replace(" ", ""); + ItemLoad(AppID, ""); + + string[] fileDirPaths = this.FileDirectory.Split(';'); + ImportDirectory(fileDirPaths, mpGuiMode); + } + finally + { + if (mpGuiMode) + { + CloseProgressDialog(); + } + } + + } + + + override public string CurrentFilePath() + { + if (filePath != "") + { + return filePath; + } + else + { + return base.CurrentFilePath(); + } + } + + + override public string DefaultFilepath() + { + return this.FileDirectory; + } + + override public bool FileBrowseAllowed() + { + return true; + } + + override public bool ProfileLoadingAllowed() + { + return true; + } + + override public void Refresh(bool mpGuiMode) + { + base.Refresh(mpGuiMode); + DeleteOrphaned(); + DoDirCacheImport(mpGuiMode); + FixFileLinks(); + LoadFiles(); + } + } +} \ No newline at end of file Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemFactory.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemFactory.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemFactory.cs 2007-07-22 19:06:56 UTC (rev 752) @@ -0,0 +1,192 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using SQLite.NET; +using System; +using GUIPrograms; + +namespace GUIPrograms.Items +{ + /// <summary> + /// Factory object that creates the matchin Application descendant class + /// depending on the sourceType parameter + /// Descendant classes differ in LOADING and REFRESHING filelists + /// </summary> + public class ApplicationItemFactory + { + static public ApplicationItemFactory AppFactory = new ApplicationItemFactory(); + + // singleton. Dont allow any instance of this class + private ApplicationItemFactory() { } + + static ApplicationItemFactory() + { + // nothing to create...... + } + + public BaseItem GetApplicationItem(SQLiteClient sqlDB, ItemType sourceType,SQLiteResultSet results, int iRecord) + { + BaseItem item = null; + switch (sourceType) + { + + case ItemType.DIRCACHE: + item = AppItemFactory(sqlDB, results, iRecord,ItemType.DIRCACHE); + break; + case ItemType.MAMEDIRECT: + item = AppItemFactory(sqlDB, results, iRecord,ItemType.MAMEDIRECT); + break; + case ItemType.GROUPER: + item = AppItemFactory(sqlDB, results, iRecord,ItemType.GROUPER); + break; + case ItemType.GAMEBASE: + item = AppItemFactory(sqlDB, results, iRecord,ItemType.GAMEBASE); + break; + case ItemType.FILEITEM: + item = FileItemFactory(sqlDB,results, iRecord); + break; + case ItemType.FILELINKITEM: + item = FilelinkItemFactory(sqlDB, results, iRecord); + break; + case ItemType.FILTERITEM: + item = FilterItemFactory(sqlDB, results, iRecord); + break; + } + return item; + } + + private ApplicationItem AppItemFactory(SQLiteClient sqldb, SQLiteResultSet results, int recordIndex, ItemType sourceType) + { + ApplicationItem item = null;//= (ApplicationItem)appFactory.GetApplicationItem(sqlDB, ProgramUtils.GetSourceType(results, recordIndex, "applicationItemType"), null, 0); + + switch (sourceType) + { + case ItemType.DIRCACHE: + item = new ApplicationItemDirectoryCache(sqldb); + break; + case ItemType.MAMEDIRECT: + item = new ApplicationItemMame(sqldb); + break; + case ItemType.GROUPER: + item = new ApplicationItemGrouper(sqldb); + break; + case ItemType.GAMEBASE: + item = new ApplicationItemGameBase(sqldb); + break; + } + + //fetches from db,, + if (results != null) + { + item.Enabled = ProgramUtils.GetBool(results, recordIndex, "enabled"); + item.AppID = ProgramUtils.GetIntDef(results, recordIndex, "applicationId", -1); + item.FatherID = ProgramUtils.GetIntDef(results, recordIndex, "fatherNodeId", -1); + item.Title = ProgramUtils.Get(results, recordIndex, "title"); + item.Filename = ProgramUtils.Get(results, recordIndex, "filename"); + item.Arguments = ProgramUtils.Get(results, recordIndex, "arguments"); + item.WindowStyle = ProgramUtils.GetProcessWindowStyle(results, recordIndex, "windowstyle"); + item.StartupDir = ProgramUtils.Get(results, recordIndex, "startupdir"); + item.UseShellExecute = ProgramUtils.GetBool(results, recordIndex, "useShellExecute"); + item.UseQuotes = ProgramUtils.GetBool(results, recordIndex, "useQuotes"); + item.SourceType = ProgramUtils.GetSourceType(results, recordIndex, "applicationItemType"); + item.Source = ProgramUtils.Get(results, recordIndex, "source"); + item.Imagefile = ProgramUtils.Get(results, recordIndex, "imagefile"); + item.FileDirectory = ProgramUtils.Get(results, recordIndex, "filedirectory"); + item.ImageDirectory = ProgramUtils.Get(results, recordIndex, "imagedirectory"); + item.ValidExtensions = ProgramUtils.Get(results, recordIndex, "validextensions"); + item.ImportValidImagesOnly = ProgramUtils.GetBool(results, recordIndex, "importvalidimagesonly"); + item.Position = ProgramUtils.GetIntDef(results, recordIndex, "iposition", 0); + item.RefreshGUIAllowed = ProgramUtils.GetBool(results, recordIndex, "refreshGUIAllowed"); + item.SystemDefault = ProgramUtils.Get(results, recordIndex, "systemdefault"); + item.WaitForExit = ProgramUtils.GetBool(results, recordIndex, "waitforexit"); + item.PreLaunch = ProgramUtils.Get(results, recordIndex, "preLaunch"); + item.PostLaunch = ProgramUtils.Get(results, recordIndex, "postLaunch"); + } + return item; + } + + private FileItem FileItemFactory(SQLiteClient sqlDB,SQLiteResultSet results, int iRecord) + { + FileItem newFile = new FileItem(sqlDB); + newFile.FileID = ProgramUtils.GetIntDef(results, iRecord, "fileid", -1); + newFile.AppID = ProgramUtils.GetIntDef(results, iRecord, "applicationId", -1); + newFile.Title = ProgramUtils.Get(results, iRecord, "title"); + newFile.Filename = ProgramUtils.Get(results, iRecord, "filename"); + newFile.Imagefile = ProgramUtils.Get(results, iRecord, "imagefile"); + newFile.MainGenre = ProgramUtils.Get(results, iRecord, "mainGenre"); + newFile.MainGenreId = ProgramUtils.GetIntDef(results, iRecord, "mainGenreId", 1); + newFile.SubGenre = ProgramUtils.Get(results, iRecord, "subGenre"); + newFile.SubGenreId = ProgramUtils.GetIntDef(results, iRecord, "subGenreId", 1); + newFile.Country = ProgramUtils.Get(results, iRecord, "country"); + newFile.ManufacturerId = ProgramUtils.GetIntDef(results, iRecord, "manufacturerId", 1); + newFile.Manufacturer = ProgramUtils.Get(results, iRecord, "manufacturer"); + newFile.Year = ProgramUtils.GetIntDef(results, iRecord, "year", -1); + newFile.Rating = ProgramUtils.GetIntDef(results, iRecord, "rating", 5); + newFile.Overview = ProgramUtils.Get(results, iRecord, "overview"); + newFile.Platform = ProgramUtils.Get(results, iRecord, "platform"); + newFile.PlatformId = ProgramUtils.GetIntDef(results, iRecord, "platformId", 1); + + newFile.IsFolder = ProgramUtils.GetBool(results, iRecord, "isfolder"); + newFile.CategoryData = ProgramUtils.Get(results, iRecord, "categorydata"); + newFile.GameInfoURL = ProgramUtils.Get(results, iRecord, "gameInfoUrl"); + return newFile; + } + + private FilterItem FilterItemFactory(SQLiteClient sqlDB,SQLiteResultSet results, int iRecord) + { + FilterItem filterItem = new FilterItem(sqlDB); + filterItem.Title = ProgramUtils.Get(results, iRecord, "title"); + // newFile.LastTimeLaunched = ProgramUtils.GetDateDef(results, iRecord, "lastTimeLaunched", DateTime.MinValue); + //newFile.LaunchCount = ProgramUtils.GetIntDef(results, iRecord, "launchcount", 0); ; + return filterItem; + } + + + private FilelinkItem FilelinkItemFactory(SQLiteClient sqlDB, SQLiteResultSet results, int iRecord) + { + FilelinkItem newLink = new FilelinkItem(sqlDB); + newLink.FileID = ProgramUtils.GetIntDef(results, iRecord, "fileId", -1); + newLink.AppID = ProgramUtils.GetIntDef(results, iRecord, "grouperAppId", -1); + newLink.TargetAppID = ProgramUtils.GetIntDef(results, iRecord, "targetAppId", -1); + newLink.Title = ProgramUtils.Get(results, iRecord, "title"); + newLink.Filename = ProgramUtils.Get(results, iRecord, "filename"); + newLink.Imagefile = ProgramUtils.Get(results, iRecord, "imagefile"); + newLink.MainGenre = ProgramUtils.Get(results, iRecord, "mainGenre"); + newLink.SubGenre = ProgramUtils.Get(results, iRecord, "subGenre"); + newLink.Country = ProgramUtils.Get(results, iRecord, "country"); + newLink.ManufacturerId = ProgramUtils.GetIntDef(results, iRecord, "manufacturerId", 1); + newLink.Manufacturer = ProgramUtils.Get(results, iRecord, "manufacturer"); + newLink.Year = ProgramUtils.GetIntDef(results, iRecord, "year", -1); + newLink.Rating = ProgramUtils.GetIntDef(results, iRecord, "rating", 5); + newLink.Overview = ProgramUtils.Get(results, iRecord, "overview"); + newLink.Platform = ProgramUtils.Get(results, iRecord, "platform"); + newLink.PlatformId = ProgramUtils.GetIntDef(results, iRecord, "platformId", 1); + newLink.LastTimeLaunched = ProgramUtils.GetDateDef(results, iRecord, "lastTimeLaunched", DateTime.MinValue); + newLink.LaunchCount = ProgramUtils.GetIntDef(results, iRecord, "launchcount", 0); + newLink.IsFolder = ProgramUtils.GetBool(results, iRecord, "isfolder"); + return newLink; + } + } +} \ No newline at end of file Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGameBase.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGameBase.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGameBase.cs 2007-07-22 19:06:56 UTC (rev 752) @@ -0,0 +1,134 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.IO; +using SQLite.NET; + +using MediaPortal.Dialogs; +using MediaPortal.GUI.Library; + +using GUIPrograms; +using GUIPrograms.Database; +using GUIPrograms.Imports; + +namespace GUIPrograms.Items +{ + /// <summary> + /// Summary description for ApplicationItemGameBase. + /// </summary> + public class ApplicationItemGameBase : ApplicationItem + { + GUIDialogProgress guiDialogProgress = null; + + public ApplicationItemGameBase(SQLiteClient initSqlDB) + : base(initSqlDB) + { + // nothing to create here... + } + + private void ShowProgressDialog() + { + guiDialogProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS); + guiDialogProgress.ShowWaitCursor = true; + guiDialogProgress.SetHeading(GUILocalizeStrings.Get(13015)); + guiDialogProgress.SetLine(0, GUILocalizeStrings.Get(13015)); + guiDialogProgress.SetLine(1, ""); + guiDialogProgress.SetLine(2, ""); + guiDialogProgress.StartModal(GetID); + guiDialogProgress.ShowProgressBar(true); + guiDialogProgress.Progress(); + } + + private void DoGamebaseImport(bool bGUIMode) + { + if (sqlDB == null) + return; + if (this.AppID < 0) + return; + if ((this.SourceType != ItemType.GAMEBASE) || (Source == "") || (!File.Exists(Source))) + return; + // show progress dialog and run the import... + if (bGUIMode) + { + ShowProgressDialog(); + } + try + { + GamebaseImport objImporter = new GamebaseImport(this, sqlDB); + objImporter.OnReadNewFile += new GamebaseImport.MyEventHandler(ReadNewFile); + try + { + objImporter.Start(); + } + finally + { + objImporter.OnReadNewFile -= new GamebaseImport.MyEventHandler(ReadNewFile); + } + } + finally + { + if (bGUIMode) + { + guiDialogProgress.Close(); + } + } + } + void ReadNewFile(string informationMessage, int progressBarCtr) + { + if (guiDialogProgress != null) + { + guiDialogProgress.SetLine(2, String.Format("{0} {1}", GUILocalizeStrings.Get(13005), informationMessage)); // "last imported file {0}" + /* if ((curPos > 0) && (maxPos > 0)) + { + int perc = 100 * curPos / maxPos; + guiDialogProgress.SetPercentage(perc); + }*/ + guiDialogProgress.Progress(); + } + SendRefreshInfo(String.Format("{0} {1}", GUILocalizeStrings.Get(13005), informationMessage), progressBarCtr); + } + + void DisplayText(string informationMessage, int progressBarCtr) + { + SendRefreshInfo(informationMessage, progressBarCtr); + } + + + override public bool ProfileLoadingAllowed() + { + return true; + } + + override public void Refresh(bool bGUIMode) + { + base.Refresh(bGUIMode); + DeleteFiles(); + DoGamebaseImport(bGUIMode); + FixFileLinks(); + LoadFiles(); + } + } +} \ No newline at end of file Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGrouper.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGrouper.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Items/ApplicationItemGrouper.cs 2007-07-22 19:06:56 UTC (rev 752) @@ -0,0 +1,178 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free S... [truncated message content] |