예제 #1
0
파일: Utils.cs 프로젝트: MrPady/c-Srun4K
 public static CreationReturnInfo OpenRegKey(string name, bool writable, RegistryHive hive = RegistryHive.CurrentUser)
 {
     // we are building x86 binary for both x86 and x64, which will
     // cause problem when opening registry key
     // detect operating system instead of CPU
     if (string.IsNullOrEmpty(name))
     {
         return(CreationReturnInfo.Create(null, false, 0x0030004));
     }
     try
     {
         RegistryKey userKey = RegistryKey.OpenBaseKey(hive,
                                                       Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32)
                               .OpenSubKey(name, writable);
         return(CreationReturnInfo.Create(userKey));
     }
     catch (ArgumentException ae)
     {
         return(CreationReturnInfo.Create(null, false, 0x0030005));
     }
     catch (Exception e)
     {
         return(CreationReturnInfo.Create(null, false, 0x0030006));
     }
 }
예제 #2
0
 public static CreationReturnInfo CreateFromJson(string json)
 {
     try
     {
         Config config = JsonConvert.DeserializeObject <Config>(json);
         return(CreationReturnInfo.Create(config));
     }
     catch (Exception e)
     {
         return(CreationReturnInfo.Create(null, false, 0x0010001, e.ToString()));
     }
 }
예제 #3
0
파일: Utils.cs 프로젝트: MrPady/c-Srun4K
        public static CreationReturnInfo ReadFile(string path)
        {
            if (!File.Exists(path))
            {
                return(CreationReturnInfo.Create(null, false, 0x0030001));
            }

            string result = null;

            try
            {
                result = File.ReadAllText(path, Encoding.UTF8);
            }
            catch (Exception e)
            {
                return(CreationReturnInfo.Create(null, false, 0x0030002));
            }

            return(CreationReturnInfo.Create(result));
        }