file.exists problem (1 Viewer)

IanJ

MP Donator
  • Premium Supporter
  • October 22, 2010
    206
    30
    Home Country
    Scotland Scotland
    Hi all,

    Just doing some very basic testing here as I'm new to C# and MP dev. I write mainly C++ for Arduino's.....anyways:-

    To demonstrate my problem, no matter what I do it just can't see the file.

    Code:
                if (File.Exists("C:/Program Files/Team MediaPortal/MediaPortal/test.txt"))
                {
                    System.Media.SystemSounds.Question.Play();
                }

    Any ideas? (be gentle with me!)

    Ian.
     

    Jay_UK

    Test Group
  • Team MediaPortal
  • October 6, 2009
    1,781
    283
    Derby
    Home Country
    United Kingdom United Kingdom
    Hi there,

    I'm not a C# dev, but try/check:

    Have you got a reference to System.IO (try putting "using System.IO;" at the beginning of your file)?
    Have you tried changing the / to a \\ in the file path?

    J.
     

    IanJ

    MP Donator
  • Premium Supporter
  • October 22, 2010
    206
    30
    Home Country
    Scotland Scotland
    Hi there,

    I'm not a C# dev, but try/check:

    Have you got a reference to System.IO (try putting "using System.IO;" at the beginning of your file)?
    Have you tried changing the / to a \\ in the file path?

    J.

    Hi,

    Yes, I've tried both those & system.IO is in place. I've also tried removing the path completely (as I think the path I'm using is default anyway).

    The following works, so I know that folder can be reached.

    Code:
    System.Diagnostics.Process.Start("C:/Program Files/Team MediaPortal/MediaPortal/scstoptvservice.cmd");
    System.Threading.Thread.Sleep(2000);
    System.Diagnostics.Process.Start("C:/Program Files/Team MediaPortal/MediaPortal/scstarttvservice.cmd");

    What I am REALLY trying to do (not being a C# dev) is have 2 buttons on the screen and have a way of remembering which one was pressed last even if MP is restarted etc.......so I thought it would be easy to use file.exist as a way of detecting that. I don't really want to go near the database.

    Ian.
     

    SilentException

    Retired Team Member
  • Premium Supporter
  • October 27, 2008
    2,617
    1,130
    Rijeka, Croatia
    Home Country
    Croatia Croatia
    It might still be permissions problem of a sort. What OS? Do you have UAC on? Have you tried checking File.Exists(@"c:\test.txt") or File.Exists(@"c:\temp\test.txt")?
     

    Jay_UK

    Test Group
  • Team MediaPortal
  • October 6, 2009
    1,781
    283
    Derby
    Home Country
    United Kingdom United Kingdom
    Hi there,

    So you are trying to create a "token" to record which button was pressed even if the main the process/owner is restarted? ie: A flag file type arrangment (button1 creates a file called button1.flag)? Have you thought about writing to the registry instead?

    J.
     

    IanJ

    MP Donator
  • Premium Supporter
  • October 22, 2010
    206
    30
    Home Country
    Scotland Scotland
    Hi,

    Yes thats exactly what I'm trying to do.

    However, more progress..............so, I managed to modify the buttons to do what I wanted them to do, but the code I added for remembering the last pressed doesn't work because where I put it isn't being run.......!
    I am basically using the demo here and thought I had identified a part of the code that was repeatedly being run, a main loop if you will......but obviously not!

    So, can anyone tell me what part of the following code is looping when the page is accessed.....

    Jings!, C# is different to C++ on Arduino's eh!.......I can't believe I am being stumped by such a small thing!!!

    Code:
    using System;
    using System.Windows.Forms;
    using MediaPortal.GUI.Library;
    using MediaPortal.Dialogs;
    
    namespace OurPlugin
    {
      public class Class1 : GUIWindow, ISetupForm
      {
        [SkinControlAttribute(2)] protected GUIButtonControl buttonOne=null;
        [SkinControlAttribute(3)] protected GUIButtonControl buttonTwo=null;
    
        public Class1()
        {
    
        }
    
        #region ISetupForm Members
    
        // Returns the name of the plugin which is shown in the plugin menu
        public string PluginName()
        {
          return "MyFirstPlugin";
        }
    
        // Returns the description of the plugin is shown in the plugin menu
        public string Description()
        {
          return "My First plugin tutorial";
        }
    
        // Returns the author of the plugin which is shown in the plugin menu
        public string Author()
        {
          return "Frodo";
        }
    
        // show the setup dialog
        public void ShowPlugin()
        {
          MessageBox.Show("Nothing to configure, this is just an example");
        }
    
        // Indicates whether plugin can be enabled/disabled
        public bool CanEnable()
        {
          return true;
        }
    
        // Get Windows-ID
        public int GetWindowId()
        {
          // WindowID of windowplugin belonging to this setup
          // enter your own unique code
          return 5678;
        }
    
        // Indicates if plugin is enabled by default;
        public bool DefaultEnabled()
        {
          return true;
        }
    
        // indicates if a plugin has it's own setup screen
        public bool HasSetup()
        {
          return true;
        }
    
        /// <summary>
        /// If the plugin should have it's own button on the main menu of Mediaportal then it
        /// should return true to this method, otherwise if it should not be on home
        /// it should return false
        /// </summary>
        /// <param name="strButtonText">text the button should have</param>
        /// <param name="strButtonImage">image for the button, or empty for default</param>
        /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
        /// <param name="strPictureImage">subpicture for the button or empty for none</param>
        /// <returns>true : plugin needs it's own button on home
        /// false : plugin does not need it's own button on home</returns>
    
        public bool GetHome(out string strButtonText, out string strButtonImage,
          out string strButtonImageFocus, out string strPictureImage)
        {
          strButtonText=PluginName();
          strButtonImage=String.Empty;
          strButtonImageFocus=String.Empty;
          strPictureImage=String.Empty;
          return true;
        }
    
        // With GetID it will be an window-plugin / otherwise a process-plugin
        // Enter the id number here again
         public override int GetID
        {
          get
          {
            return 5678;
          }
    
          set
          {
          }
        }
    
        #endregion
    
        public override bool Init()
        {
          return Load(GUIGraphicsContext.Skin+@"\ourplugin.xml");
        }
    
        protected override void OnClicked(int controlId, GUIControl control,
          MediaPortal.GUI.Library.Action.ActionType actionType)
        {
          if (control==buttonOne)
            OnButtonOne();
          if (control==buttonTwo)
            OnButtonTwo();
          base.OnClicked (controlId, control, actionType);
        }
    
        private void OnButtonOne()
        {
          GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow(
            (int)GUIWindow.Window.WINDOW_DIALOG_OK);
          dlg.SetHeading("Button has been pressed");
          dlg.SetLine(1, "You pressed button 1");
          dlg.SetLine(2, String.Empty);
          dlg.SetLine(3, String.Empty);
          dlg.DoModal(GUIWindowManager.ActiveWindow);
        }
    
        private void OnButtonTwo()
        {
          GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow(
            (int)GUIWindow.Window.WINDOW_DIALOG_OK);
          dlg.SetHeading("Button has been pressed");
          dlg.SetLine(1, "You pressed button 2");
          dlg.SetLine(2, String.Empty);
          dlg.SetLine(3, String.Empty);
          dlg.DoModal(GUIWindowManager.ActiveWindow);
        }
    
      }
    
    }
     

    Quarter

    MP Donator
  • Premium Supporter
  • June 21, 2010
    722
    138
    Queenstown
    Home Country
    New Zealand New Zealand
    Would OnPageLoad and OnPageDispose be enough? To recall and to save. Not sure if the OnPageDispose is the right code, But you get my point.
     

    Users who are viewing this thread

    Top Bottom