Exemple #1
0
        public void Open(string parameter)
        {
            string location = ActionChecker.GetSecondaryParam(parameter)[0], arguments = (ActionChecker.GetSecondaryParam(parameter).Length > 1 ? ActionChecker.GetSecondaryParam(parameter)[1] : null);
            string fileLocation = (!location.Contains(@":\") || !location.Contains(@":/")) ? "" : location;

            if (fileLocation == "")
            {
                string combinedPath = "";
                try {
                    combinedPath = Path.Combine(MainProgram.shortcutLocation, location);
                } catch {
                    Error("Given path (" + location + ") is invalid (could not combine)");
                }

                if (combinedPath != "")
                {
                    fileLocation = combinedPath;
                }
            }

            if (fileLocation != "")
            {
                if (MainProgram.IsValidPath(location))
                {
                    if (File.Exists(fileLocation) || Directory.Exists(fileLocation) || Uri.IsWellFormedUriString(fileLocation, UriKind.Absolute))
                    {
                        if (!MainProgram.testingAction)
                        {
                            try {
                                Process p = new Process();
                                p.StartInfo.FileName = fileLocation;
                                if (arguments != null)
                                {
                                    p.StartInfo.Arguments = arguments;
                                }
                                p.Start();
                                successMessage = "OPEN: opened file/url; " + fileLocation;
                            } catch (Exception e) {
                                MainProgram.DoDebug("Failed to open file; " + e.Message);
                                Error("Failed to open file (" + fileLocation + ")");
                            }
                        }
                        else
                        {
                            successMessage = "OPEN: simulated opening file; " + fileLocation;
                        }
                    }
                    else
                    {
                        Error("File or directory doesn't exist (" + fileLocation + ")");
                    }
                }
                else
                {
                    Error("Given path is invalid");
                }
            }
        }