Beispiel #1
0
        /*private void RestartService()
         * {
         *  ServiceController controller = new ServiceController("priv10");
         *  if (controller.Status == ServiceControllerStatus.Stopped)
         *      controller.Start();
         *  Progress?.Invoke(this, new ProgressArgs() { Progress = 90, Message = "Service Restarted" });
         * }*/

        private void Remove()
        {
            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 10, Message = "Removing priv10 Service..."
            });
            if (!Uninstall())
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = -1, Message = "Failed to remove Service", Show = true
                });
            }
            Thread.Sleep(100);


            List <string> fileList = ReadFileList(); // get a list of old files

            if (fileList != null)
            {
                for (int i = 0; i < fileList.Count; i++)
                {
                    var filePath = fileList[i];

                    // don't touch files outside the instalation directory
                    if (!filePath.Substring(0, Data.InstallationPath.Length).Equals(Data.InstallationPath, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    Progress?.Invoke(this, new ProgressArgs()
                    {
                        Progress = 20 + 30 * (i + 1) / fileList.Count, Message = "Removing: " + filePath
                    });
                    if (!MiscFunc.SafeDelete(filePath))
                    {
                        Progress?.Invoke(this, new ProgressArgs()
                        {
                            Progress = -1, Message = "Removing failed!", Show = true
                        });
                    }
                }
                MiscFunc.SafeDelete(Data.InstallationPath + @"\" + InstalListFile);
                MiscFunc.SafeDelete(Data.InstallationPath + @"\" + LicenseFile);

                // In case the user installed the application where he shouldn't have
                if (IsUnsafePath(Data.InstallationPath))
                {
                    Progress?.Invoke(this, new ProgressArgs()
                    {
                        Progress = -1, Message = "Can not clean up instalation folder!", Show = true
                    });
                }
                else if (!MiscFunc.DeleteEmptyDir(Data.InstallationPath))
                {
                    string Message = "Failed to remove the application directory" + Data.InstallationPath + "\r\nThe folder is eider not empty or in use.";
                    Progress?.Invoke(this, new ProgressArgs()
                    {
                        Progress = -1, Message = Message, Show = true
                    });
                }
            }
            else
            {
                string Message = "install.lst not found in: " + Data.InstallationPath + "\r\nPlease remove the applciatrion files manually.";
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = -1, Message = Message, Show = true
                });
            }



            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 50, Message = "Removing Start Menu Entries..."
            });
            string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms), SetupData.AppTitle + ".lnk");

            MiscFunc.SafeDelete(lnkPath);
            Thread.Sleep(100);

            if (Data.RemoveUserData)
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = 60, Message = "Removing configuration data..."
                });

                string progData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                if (progData == null)
                {
                    progData = @"C:\ProgramData";
                }

                var IniPath = progData + "\\" + SetupData.AppKey;
                if (Directory.Exists(IniPath))
                {
                    var userFiles = MiscFunc.EnumAllFiles(IniPath);
                    foreach (var filePath in userFiles)
                    {
                        MiscFunc.SafeDelete(filePath);
                    }

                    if (!MiscFunc.DeleteEmptyDir(IniPath))
                    {
                        string Message = "Failed to remove the application data" + IniPath + "\r\nThe folder is eider not empty or in use.";
                        Progress?.Invoke(this, new ProgressArgs()
                        {
                            Progress = -1, Message = Message, Show = true
                        });
                    }
                }
            }

            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 80, Message = "Cleaningup Registry..."
            });
            if (!Data.CleanupRegistry())
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = -1, Message = "Failed to cleanup Registry", Show = true
                });
            }
            Thread.Sleep(100);

            if (Data.ResetFirewall)
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = 90, Message = "Restoring default Firewall configuration..."
                });
                MiscFunc.Exec("netsh.exe", "advfirewall reset");
            }

            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 100, Message = "Uninstalation completed."
            });
            Thread.Sleep(100);
        }
Beispiel #2
0
        public bool ExtractFile(FileInfo file, string installationPath)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    string targetPath = installationPath + @"\" + file.FileName;
                    if (File.Exists(targetPath))
                    {
                        MiscFunc.SafeDelete(targetPath);
                    }
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                    }

                    if (IsValid())
                    {
                        using (Stream inStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PrivateSetup.Resources." + file.Alias))
                        {
                            using (Stream rawStream = new DeflateStream(inStream, CompressionMode.Decompress))
                            {
                                MemoryStream memStream = new MemoryStream();
                                rawStream.CopyTo(memStream);
                                memStream.Seek(0, SeekOrigin.Begin);

                                using (var md5 = MD5.Create())
                                {
                                    using (Stream outStream = File.Create(targetPath))
                                    {
                                        memStream.CopyTo(outStream);
                                    }

                                    using (var testStream = File.OpenRead(targetPath))
                                    {
                                        byte[] hash    = md5.ComputeHash(testStream);
                                        var    hashStr = BitConverter.ToString(hash).Replace("-", "");

                                        if (!file.Hash.Equals(hashStr))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        File.Copy(App.appPath + FilePath + @"\" + file.FileName, targetPath);
                    }

                    return(true);
                }
                catch
                {
                    Thread.Sleep(1000 * (i + 1));
                }
            }
            return(false);
        }
Beispiel #3
0
        private void Update()
        {
            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 0, Message = "Clossing running instances..."
            });
            Shutdown();

            List <string> oldList = ReadFileList(); // get a list of old files

            List <string> fileList = Extract(true); // note: this updates install.lst

            // remove old files
            if (oldList != null)
            {
                foreach (var filePath in oldList)
                {
                    if (!fileList.Contains(filePath, StringComparer.OrdinalIgnoreCase))
                    {
                        // don't touch files outside the instalation directory
                        if (!filePath.Substring(0, Data.InstallationPath.Length).Equals(Data.InstallationPath, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        Progress?.Invoke(this, new ProgressArgs()
                        {
                            Progress = -1, Message = "Removing: " + filePath
                        });
                        if (!MiscFunc.SafeDelete(filePath))
                        {
                            Progress?.Invoke(this, new ProgressArgs()
                            {
                                Progress = -1, Message = "Removing failed!", Show = true
                            });
                        }
                    }
                }
            }


            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 75, Message = "Updating Registry..."
            });
            if (!Data.UpdateRegistry())
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = -1, Message = "Failed to update the Registry", Show = true
                });
            }
            Thread.Sleep(100);

            /*try
             * {
             *  RestartService();
             * }
             * catch { }*/

            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 85, Message = "Updating priv10 Service..."
            });
            if (!UpdateSvc())
            {
                Progress?.Invoke(this, new ProgressArgs()
                {
                    Progress = -1, Message = "Failed to update Service", Show = true
                });
            }
            Thread.Sleep(100);

            Progress?.Invoke(this, new ProgressArgs()
            {
                Progress = 100, Message = "Update completed."
            });
            Thread.Sleep(100);
        }