frmTray.cs :  » Game » Media-File-XStream » MFXSTray » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » Media File XStream 
Media File XStream » MFXSTray » frmTray.cs
/* 
Media File XStream, Network file stream server supporting XBMSP
Copyright (C) 2004  j3g

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 of the License, 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

This project can be found on SourceForge.
http://sourceforge.net/projects/mfxstream
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Win32;
using MFXStream;

namespace MFXSTray{
  /// <summary>
  /// Summary description for frmTray.
  /// </summary>
  public class frmTray : System.Windows.Forms.Form
  {
    private System.Windows.Forms.NotifyIcon niTask;
    private System.Windows.Forms.ContextMenu ctxMenu;
    private System.ComponentModel.IContainer components;
    private System.Windows.Forms.MenuItem menuItem4;
    private System.Windows.Forms.MenuItem menuItem5;
    private System.Windows.Forms.MenuItem mnuStartStop;
    private System.Windows.Forms.MenuItem mnuServerInstall;
    private System.Windows.Forms.MenuItem mnuExit;
    private System.Windows.Forms.MenuItem mnuRestart;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem mnuStartMFXStream;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem mnuStartup;
    private System.Windows.Forms.MenuItem menuItem8;
    private System.Windows.Forms.MenuItem mnuOption;

    private CServiceHandler _sh; 
    private String GetAppPath
    {
      get 
      {
        return (System.IO.Path.GetDirectoryName( 
          System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6));
      }     
    }


    public frmTray()
    {
      this._sh = new CServiceHandler(GetAppPath + "\\MFXStreamSrv.exe", "Media File XStream Service");
      InitializeComponent();

      RegistryKey rkRun = Registry.LocalMachine.OpenSubKey("software\\microsoft\\windows\\currentversion\\run", true);
      ArrayList al = new ArrayList(rkRun.GetValueNames());
      if (al.Contains("MFXSTray"))
        rkRun.SetValue("MFXSTray", GetAppPath + "\\MFXSTray.exe");
    }
    protected void mnuExit_Click(Object sender, System.EventArgs e)
    {
      niTask.Visible = false;
      this.Dispose();
      Application.Exit();
    }
    protected override void Dispose( bool disposing )
    {
      if(disposing)
        niTask.Dispose();

      base.Dispose(disposing);
    }
    #region Main and InitializeComponent
    [STAThread]
    static void Main()
    {
      frmTray f = new frmTray();
      Application.Run();
    }

    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmTray));
      this.niTask = new System.Windows.Forms.NotifyIcon(this.components);
      this.ctxMenu = new System.Windows.Forms.ContextMenu();
      this.mnuOption = new System.Windows.Forms.MenuItem();
      this.mnuServerInstall = new System.Windows.Forms.MenuItem();
      this.menuItem5 = new System.Windows.Forms.MenuItem();
      this.mnuStartup = new System.Windows.Forms.MenuItem();
      this.menuItem1 = new System.Windows.Forms.MenuItem();
      this.menuItem3 = new System.Windows.Forms.MenuItem();
      this.mnuStartMFXStream = new System.Windows.Forms.MenuItem();
      this.menuItem4 = new System.Windows.Forms.MenuItem();
      this.mnuRestart = new System.Windows.Forms.MenuItem();
      this.mnuStartStop = new System.Windows.Forms.MenuItem();
      this.menuItem2 = new System.Windows.Forms.MenuItem();
      this.mnuExit = new System.Windows.Forms.MenuItem();
      this.menuItem8 = new System.Windows.Forms.MenuItem();
      // 
      // niTask
      // 
      this.niTask.ContextMenu = this.ctxMenu;
      this.niTask.Icon = ((System.Drawing.Icon)(resources.GetObject("niTask.Icon")));
      this.niTask.Text = "MFXSTray";
      this.niTask.Visible = true;
      this.niTask.MouseDown += new System.Windows.Forms.MouseEventHandler(this.niTask_MouseDown);
      // 
      // ctxMenu
      // 
      this.ctxMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                          this.mnuOption,
                                          this.menuItem5,
                                          this.mnuServerInstall,
                                          this.menuItem8,
                                          this.mnuStartMFXStream,
                                          this.menuItem4,
                                          this.mnuRestart,
                                          this.mnuStartStop,
                                          this.menuItem2,
                                          this.mnuExit});
      // 
      // mnuOption
      // 
      this.mnuOption.Index = 0;
      this.mnuOption.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.mnuStartup,
                                            this.menuItem1,
                                            this.menuItem3});
      this.mnuOption.Text = "Options";
      // 
      // mnuServerInstall
      // 
      this.mnuServerInstall.Index = 2;
      this.mnuServerInstall.Text = "Install MFXStream Service";
      this.mnuServerInstall.Click += new System.EventHandler(this.mnuServerInstall_Click);
      // 
      // menuItem5
      // 
      this.menuItem5.Index = 1;
      this.menuItem5.Text = "-";
      // 
      // mnuStartup
      // 
      this.mnuStartup.Index = 0;
      this.mnuStartup.Text = "Run MFXSTray on startup";
      this.mnuStartup.Click += new System.EventHandler(this.mnuStartup_Click);
      // 
      // menuItem1
      // 
      this.menuItem1.Index = 1;
      this.menuItem1.Text = "-";
      // 
      // menuItem3
      // 
      this.menuItem3.Index = 2;
      this.menuItem3.Text = "About";
      this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
      // 
      // mnuStartMFXStream
      // 
      this.mnuStartMFXStream.Index = 4;
      this.mnuStartMFXStream.Text = "Start MFXStream";
      this.mnuStartMFXStream.Click += new System.EventHandler(this.mnuStartMFXStream_Click);
      // 
      // menuItem4
      // 
      this.menuItem4.Index = 5;
      this.menuItem4.Text = "-";
      // 
      // mnuRestart
      // 
      this.mnuRestart.Index = 6;
      this.mnuRestart.Text = "Restart MFXStream service";
      this.mnuRestart.Click += new System.EventHandler(this.mnuRestart_Click);
      // 
      // mnuStartStop
      // 
      this.mnuStartStop.Index = 7;
      this.mnuStartStop.Text = "Start MFXStream service";
      this.mnuStartStop.Click += new System.EventHandler(this.mnuStartStop_Click);
      // 
      // menuItem2
      // 
      this.menuItem2.Index = 8;
      this.menuItem2.Text = "-";
      // 
      // mnuExit
      // 
      this.mnuExit.Index = 9;
      this.mnuExit.Text = "Exit";
      this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
      // 
      // menuItem8
      // 
      this.menuItem8.Index = 3;
      this.menuItem8.Text = "-";
      // 
      // frmTray
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 266);
      this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
      this.Name = "frmTray";

    }
    #endregion Main and InitializeComponent

    protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
    {
      niTask.Visible = false;
      this.Dispose();
      base.OnClosing (e);
      Application.Exit();
    }

    private void mnuServerInstall_Click(object sender, System.EventArgs e)
    {
      if (!this._sh.IsInstalled)
      {
        try
        {
          MessageBox.Show(this._sh.Install(false), "MFXStream");
        }
        catch
        {
          MessageBox.Show("MFXStream service could not be installed", "MFXStream");
        }
      }
      else
      {
        try
        {
          MessageBox.Show(this._sh.UnInstall(false), "MFXStream");
        }
        catch
        {
          MessageBox.Show("MFXStream service could not be removed", "MFXStream");
        }
      }
    }

    private void mnuStartStop_Click(object sender, System.EventArgs e)
    {
            if (this._sh.IsStarted)
      {
        try
        {
          MessageBox.Show(this._sh.Stop(false), "MFXStream");
        }
        catch
        {
          MessageBox.Show("MFXStream service could not be stoped", "MFXStream");
        }
      }
      else
      {
        try
        {
          MessageBox.Show(this._sh.Start(false), "MFXStream");
        }
        catch
        {
          MessageBox.Show("MFXStream service could not be started", "MFXStream");
        }
      }
    }

    private void niTask_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      RegistryKey rkRun = Registry.LocalMachine.OpenSubKey("software\\microsoft\\windows\\currentversion\\run");
      ArrayList al = new ArrayList(rkRun.GetValueNames());
      if (al.Contains("MFXSTray"))
        mnuStartup.Checked = true;
      else
        mnuStartup.Checked = false;

      if (this._sh.IsStarted)
        this.mnuStartStop.Text = "Stop MFXStream service";
      else
        this.mnuStartStop.Text = "Start MFXStream service";

      if (this._sh.IsInstalled)
      {
        this.mnuServerInstall.Text = "Uninstall MFXStream service";
        this.mnuStartStop.Enabled = true;
        if (this._sh.IsStarted)
          this.mnuRestart.Enabled = true;
        else
          this.mnuRestart.Enabled = false;

      }
      else
      {
        this.mnuServerInstall.Text = "Install MFXStream service";
        this.mnuStartStop.Enabled = false;
        this.mnuRestart.Enabled = false;
      }
    }

    private void mnuRestart_Click(object sender, System.EventArgs e)
    {
      try
      {
        MessageBox.Show(this._sh.Restart(false), "MFXStream");
      }
      catch
      {
        MessageBox.Show("MFXStream service could not be stoped", "MFXStream");
      }
    }

    private void mnuStartMFXStream_Click(object sender, System.EventArgs e)
    {
      System.Diagnostics.Process.Start("MFXStream.exe");
    }

    private void menuItem3_Click(object sender, System.EventArgs e)
    {
      frmAbout frmX = new frmAbout();
      frmX.ShowDialog(this);
    }

    private void mnuStartup_Click(object sender, System.EventArgs e)
    {
      RegistryKey rkRun = Registry.LocalMachine.OpenSubKey("software\\microsoft\\windows\\currentversion\\run", true);
      if (mnuStartup.Checked)
      {
        rkRun.DeleteValue("MFXSTray", false);
        mnuStartup.Checked = false;

      }
      else
      {
        rkRun.SetValue("MFXSTray", GetAppPath + "\\MFXSTray.exe");
        mnuStartup.Checked = true;
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.