Пример #1
0
        void LaunchWithFiles(GLib.File app, IEnumerable <GLib.File> files)
        {
            AppInfo appinfo = null;

            if (app != null)
            {
                appinfo = GLib.DesktopAppInfo.NewFromFilename(app.Path);
            }
            else
            {
                if (!files.Any())
                {
                    return;
                }

                // if we weren't given an app info, query the file for the default handler
                try {
                    appinfo = files.First().QueryDefaultHandler(null);
                } catch {
                    // file probably doesnt exist
                    return;
                }
            }

            try {
                GLib.List launchList;

                if (!files.Any())
                {
                    appinfo.Launch(null, null);

                    // check if the app supports files or Uris
                }
                else if (appinfo.SupportsFiles)
                {
                    launchList = new GLib.List(new GLib.File[] {}, typeof(GLib.File), true, false);
                    foreach (GLib.File f in files)
                    {
                        launchList.Append(f);
                    }

                    appinfo.Launch(launchList, null);
                    launchList.Dispose();
                }
                else if (appinfo.SupportsUris)
                {
                    launchList = new GLib.List(new string[] {}, typeof(string), true, true);
                    foreach (GLib.File f in files)
                    {
                        // try to use GLib.File.Uri first, if that throws an exception,
                        // catch and use P/Invoke to libdocky.  If that's still null, warn & skip the file.
                        try {
                            launchList.Append(f.Uri.ToString());
                        } catch (UriFormatException) {
                            string uri = f.StringUri();
                            if (string.IsNullOrEmpty(uri))
                            {
                                Log <SystemService> .Warn("Failed to retrieve URI for {0}.  It will be skipped.", f.Path);

                                continue;
                            }
                            launchList.Append(uri);
                        }
                    }
                    appinfo.LaunchUris(launchList, null);
                    launchList.Dispose();
                }
                else
                {
                    Log <SystemService> .Error("Error opening files. The application doesn't support files/URIs or wasn't found.");
                }
            } catch (GException e) {
                Log.Notify(string.Format("Error running: {0}", appinfo.Name), Gtk.Stock.DialogWarning, e.Message);
                Log <SystemService> .Error(e.Message);

                Log <SystemService> .Info(e.StackTrace);
            }

            (appinfo as IDisposable).Dispose();
        }
Пример #2
0
		void LaunchWithFiles (GLib.File app, IEnumerable<GLib.File> files)
		{
			AppInfo appinfo = null;
			if (app != null) {
				appinfo = GLib.DesktopAppInfo.NewFromFilename (app.Path);
			} else {
				if (!files.Any ())
					return;

				// if we weren't given an app info, query the file for the default handler
				try {
					appinfo = files.First ().QueryDefaultHandler (null);
				} catch {
					// file probably doesnt exist
					return;
				}
			}
			
			try {
				GLib.List launchList;
				
				if (!files.Any ()) {
					appinfo.Launch (null, null);

				// check if the app supports files or Uris
				} else if (appinfo.SupportsFiles) {
					launchList = new GLib.List (new GLib.File[] {}, typeof (GLib.File), true, false);
					foreach (GLib.File f in files)
						launchList.Append (f);

					appinfo.Launch (launchList, null);
					launchList.Dispose ();
					
				} else if (appinfo.SupportsUris) {
					launchList = new GLib.List (new string[] {}, typeof (string), true, true);
					foreach (GLib.File f in files) {
						// try to use GLib.File.Uri first, if that throws an exception,
						// catch and use P/Invoke to libdocky.  If that's still null, warn & skip the file.
						try {
							launchList.Append (f.Uri.ToString ());
						} catch (UriFormatException) { 
							string uri = f.StringUri ();
							if (string.IsNullOrEmpty (uri)) {
								Log<SystemService>.Warn ("Failed to retrieve URI for {0}.  It will be skipped.", f.Path);
								continue;
							}
							launchList.Append (uri);
						}
					}
					appinfo.LaunchUris (launchList, null);
					launchList.Dispose ();
					
				} else {
					Log<SystemService>.Error ("Error opening files. The application doesn't support files/URIs or wasn't found.");	
				}
				
			} catch (GException e) {
				Log.Notify (string.Format ("Error running: {0}", appinfo.Name), Gtk.Stock.DialogWarning, e.Message);
				Log<SystemService>.Error (e.Message);
				Log<SystemService>.Info (e.StackTrace);
			}

			(appinfo as IDisposable).Dispose ();
		}