コード例 #1
0
        public static bool Install(IAppToInstall app)       //TODO: Typ zwracany zmienić enuma InstalledStatus ?
        {
            try
            {
                string path = app.DownloadDirectory + "\\" + app.FileDwnlName;

                using (var process = Process.Start(path))
                {
                    if (process == null)
                    {
                        return(false);
                    }
                    process.WaitForExit();
                    if (process.ExitCode == 0)
                    {
                        IsAppInstalled(app);
                        return(true);
                    }
                }
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                Console.WriteLine(e);
                throw new FileNotFoundException();
            }
            return(false);
        }
コード例 #2
0
ファイル: Manage.cs プロジェクト: warrior888/toci_teachers
 public void SerializeModels(IAppToInstall app)
 {
     using (var write = File.OpenWrite(_appConfigPath + $"\\{app.AppName}.bin"))  // ANOTHER_POSSIBILITY: Pobierać dane z serwera - nazwe pliku instalacyjnego
     {
         var formatter = new BinaryFormatter();
         formatter.Serialize(write, app);
     }
 }
コード例 #3
0
 public void DwnloadFile(string path, IAppToInstall app)
 {
     using (WebClient wc = new WebClient())
     {
         wc.DownloadFileCompleted += (sender, e) =>
         {
             Complate?.Invoke(app, e);
         };
         wc.DownloadProgressChanged += Progress;
         wc.DownloadFileTaskAsync(new Uri("http://vps458649.ovh.net/" + app.FileDwnlName), Path.Combine(path + "\\" + app.FileDwnlName));
     }
 }
コード例 #4
0
        /// <summary>
        /// Checks whether the application is installed in system.
        /// </summary>
        /// <param name="app">Class implemented interface IAppToInstall</param>
        /// <returns>If is installed return true otherwise return false.</returns>
        public static bool IsAppInstalled(IAppToInstall app)
        {
            var path = SearchRegistry(app.AppName).ToArray();

            if (path?.Any() != true)
            {
                return(false);
            }

            app.InstalledAppPath = path.First();
            return(true);

            #region Check windows registry

            /*var machineKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") ??
             *               Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
             * var userKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
             * bool found = false;
             *
             * if (machineKey == null && userKey == null)
             *  return false;
             *
             * if (machineKey != null)
             * {
             *  found = machineKey.GetSubKeyNames()
             *      .Select(keyName => machineKey.OpenSubKey(keyName))
             *      .Select(subkey => subkey.GetValue("DisplayName") as string)
             *      .Any(displayName => displayName != null && displayName.Contains(softwareName));
             * }
             *
             * if (userKey != null && found != true)
             * {
             *  found = userKey.GetSubKeyNames()
             *      .Select(keyName => userKey.OpenSubKey(keyName))
             *      .Select(subkey => subkey.GetValue("DisplayName") as string)
             *      .Any(displayName => displayName != null && displayName.Contains(softwareName));
             * }
             *
             * return found;*/

            #endregion
        }
コード例 #5
0
ファイル: Manage.cs プロジェクト: warrior888/toci_teachers
        public void LoadAppSettings(IAppToInstall app)
        {
            try
            {
                using (var input = File.OpenRead(_appConfigPath + $"\\{app.AppName}.bin"))
                {
                    var formatter = new BinaryFormatter();

                    var appTemp = (IAppToInstall)formatter.Deserialize(input);

                    app.InstalledAppPath  = appTemp.InstalledAppPath;
                    app.DownloadDirectory = appTemp.DownloadDirectory;
                    app.IsDownloaded      = appTemp.IsDownloaded;
                }
            }
            catch (SerializationException e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #6
0
 public static void RunApp(IAppToInstall app)
 {
     Process.Start(app.InstalledAppPath);
 }