private bool IsValidRegistryKeyName(string value, out RegistryName registryName) { registryName = new RegistryName(); if (value == null) { return(false); } string[] fullAddressParts = Path.GetFileName(value).Split('_'); if (fullAddressParts.Length != 3) { return(false); } if (fullAddressParts[0] != RCC) { return(false); } if (fullAddressParts[1].Length != 2 || !int.TryParse(fullAddressParts[1], out int @int)) { return(false); } if (fullAddressParts[2].Length < 1) { return(false); } registryName = new RegistryName(fullAddressParts[1], fullAddressParts[2]); return(true); }
/// <exception cref="UnauthorizedAccessException"></exception> private BatScriptConfig TryCastToBatScriptConfig(IScriptStorageModel script, RegistryName registryName, MenuLocation location) { BatScriptConfig newConfig = null; try { IIconReference iconReference = null; if (!string.IsNullOrWhiteSpace(script.Icon)) { iconReference = new IconReference(script.Icon); } newConfig = new BatScriptConfig(registryName.Name, registryName.ID, settings, messagePrompt, iconPicker) { Label = script.Label, Icon = iconReference }; newConfig.LoadScript(); newConfig.ModifyLocation(location, true); } catch (System.Security.SecurityException) { return(null); } catch (ObjectDisposedException) { return(null); } catch (IOException) { return(null); } catch (ScriptAccessException) { return(null); } if (script.Command.Length <= 8 || script.Command.Substring(0, 5) != cmd) { return(null); } if (script.Command.Substring(7, 2) == BatScriptConfig.keepCMDOpen) { newConfig.KeepWindowOpen = true; } else if (script.Command.Substring(7, 2) == BatScriptConfig.closeCMD) { newConfig.KeepWindowOpen = false; } else { return(null); } return(newConfig); }
/// <exception cref="UnauthorizedAccessException"></exception> private PowershellScriptConfig TryCastToPowershellScriptConfig(IScriptStorageModel script, RegistryName registryName, MenuLocation location) { PowershellScriptConfig newConfig = null; try { IIconReference iconReference = null; if (!string.IsNullOrWhiteSpace(script.Icon)) { iconReference = new IconReference(script.Icon); } newConfig = new PowershellScriptConfig(registryName.Name, registryName.ID, settings, messagePrompt, iconPicker) { Label = script.Label, Icon = iconReference }; newConfig.LoadScript(); newConfig.ModifyLocation(location, true); } catch (System.Security.SecurityException) { return(null); } catch (ObjectDisposedException) { return(null); } catch (IOException) { return(null); } catch (ScriptAccessException) { return(null); } if (script.Command.Length <= 12 || script.Command.Substring(0, 12) != powershell) { return(null); } newConfig.KeepWindowOpen = script.Command.Contains(PowershellScriptConfig.noExit); return(newConfig); }