public void ReplaceHostFile(string[] args)
        {
            string newPath = "";

            foreach (var argument in args)
            {
                if (argument.Contains("-newPath"))
                {
                    newPath = argument.Substring(10, (argument.Length - 11)).Replace("%20", " ");
                    if (!FileModification.FileExists(newPath))
                    {
                        newPath = "";
                    }
                }
            }

            if (newPath == "")
            {
                Console.WriteLine("No valid path for new system file was given.");
                if (!_unitTestSetup)
                {
                    Console.ReadKey();
                    Environment.Exit(1);
                }
            }

            string hostContent = FileModification.ReadFile(newPath);

            FileModification.WriteFile(GetHostFileLocation(), hostContent);
            if (!_unitTestSetup)
            {
                Environment.Exit(0);
            }
        }
 public void CreateEmptyProfileConfigurationIfNotExists()
 {
     if (!FileModification.FileExists(GetProxyUserConfigurationPath()))
     {
         SaveUserConfiguration(new CurrentUserConfiguration());
     }
 }
        public void SetCurrentConfigurationToDefault()
        {
            if (!FileModification.FileExists(ConfigurationPath))
            {
                FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", ""));
            }
            CreateNewConfiguration();

            CopyCurrentConfigurationToTempConfig();
        }
        public void SaveCurrentConfiguration()
        {
            CopyTempConfigurationToCurrentConfig();

            if (!FileModification.FileExists(ConfigurationPath))
            {
                FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", ""));
            }
            SaveConfiguration(Configuration);

            CopyCurrentConfigurationToTempConfig();
        }
예제 #5
0
        private void SetNewestImagePath()
        {
            string imagePath = "";

            if (FileModification.FileExists($"{_oldImagePath}.jpg"))
            {
                imagePath = $"{_oldImagePath}.jpg";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.jpeg"))
            {
                imagePath = $"{_oldImagePath}.jpeg";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.gif"))
            {
                imagePath = $"{_oldImagePath}.gif";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.bmp"))
            {
                imagePath = $"{_oldImagePath}.bmp";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.png"))
            {
                imagePath = $"{_oldImagePath}.png";
            }

            if (imagePath != "")
            {
                try
                {
                    System.Drawing.Image img = System.Drawing.Image.FromFile(imagePath);
                    var bmp = new BitmapImage();
                    bmp.BeginInit();
                    bmp.UriSource = new Uri(imagePath);
                    bmp.EndInit();

                    imageToRemind.Source = bmp;
                }
                catch (Exception)
                {
                    //image is broken
                    imageToRemind.Source = null;
                }
            }
            else
            {
                //image is not in folder
                imageToRemind.Source = null;
            }
        }
        private void SetNewestImagePath()
        {
            string imagePath = "";

            if (FileModification.FileExists($"{_oldImagePath}.jpg"))
            {
                imagePath = $"{_oldImagePath}.jpg";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.jpeg"))
            {
                imagePath = $"{_oldImagePath}.jpeg";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.gif"))
            {
                imagePath = $"{_oldImagePath}.gif";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.bmp"))
            {
                imagePath = $"{_oldImagePath}.bmp";
            }
            else if (FileModification.FileExists($"{_oldImagePath}.png"))
            {
                imagePath = $"{_oldImagePath}.png";
            }

            if (imagePath != "")
            {
                try
                {
                    ImageDisplayed.Source = GetImageByStream(imagePath);
                }
                catch (Exception)
                {
                    //image is broken
                    ImageDisplayed.Source = null;
                }
            }
            else
            {
                //image is not in folder
                ImageDisplayed.Source = null;
            }
        }
        public void SetCurrentConfigurationFromConfig()
        {
            if (FileModification.FileExists(ConfigurationPath))
            {
                string configurationContent = FileModification.ReadFile(ConfigurationPath);
                if (configurationContent == "")
                {
                    CreateNewConfiguration();
                }
                else
                {
                    Configuration = JsonConvert.DeserializeObject <CurrentProgramConfiguration>(configurationContent);
                }
            }
            else
            {
                FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", ""));
                CreateNewConfiguration();
            }

            CopyCurrentConfigurationToTempConfig();
        }
        public void LoadCurrentUserConfiguration()
        {
            if (!FileModification.FileExists(GetProxyUserConfigurationPath()))
            {
                throw new WebProxyNoProfilesFileException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" does not exist.");
            }
            else
            {
                string encryptedConfigurationContent = FileModification.ReadFile(GetProxyUserConfigurationPath());
                bool   fileIsBroken = false;
                if (encryptedConfigurationContent != "")
                {
                    try
                    {
                        string configurationContent =
                            EncryptingHelper.Decrypt(encryptedConfigurationContent, _configurationPassword);
                        var configuration =
                            JsonConvert.DeserializeObject <CurrentUserConfiguration>(configurationContent);
                        ApplyUserConfiguration(configuration, false);
                    }
                    catch (Exception)
                    {
                        fileIsBroken = true;
                    }
                }
                else
                {
                    fileIsBroken = true;
                }

                if (fileIsBroken)
                {
                    throw new WebProxyBrokenProfileConfigurationException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" is broken.");
                }
            }
        }
예제 #9
0
 public bool HostFileExists()
 {
     return(FileModification.FileExists(FileModification.GetHostFileLocation()));
 }
예제 #10
0
 public bool ConfigurationIsAlreadyCreated()
 {
     return(FileModification.FileExists(ConfigurationPath));
 }