Доступ к каталогу и файлам запрещен после создания setup.exe с помощью inno.setup - PullRequest
0 голосов
/ 05 апреля 2020

Я создаю игровой лаунчер для Counter-Strike 1.6 ... Теперь у меня проблема, когда я создаю setup.exe для всей игры и открываю лаунчер, все хорошо, но когда я пытаюсь использовать какие-либо опции или пытаюсь запустить игра, которую я не могу, потому что я получил сообщение об ошибке, в котором говорится, что доступ к папкам или файлам запрещен ...

Я создал startup.exe с Inno setup!

Вот необходимость коды материалов:

home.cs

using System;
using System.IO;
using System.Windows.Forms;
using System.Text;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog(); // Shows Form2
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.ShowDialog(); // Shows Form3
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.ShowDialog(); // Shows Form4
        }

        private void button4_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://fastxhoster.com/");
        }

        private void button5_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = @"steamlop.lop";
            string cfgpath = @"cstrike/config.cfg";
            FileAttributes attributes = File.GetAttributes(cfgpath);

            if (File.Exists(path))
            {
                File.SetAttributes(cfgpath, File.GetAttributes(cfgpath) | FileAttributes.ReadOnly);
                var str = File.ReadAllText(path);
                System.Diagnostics.Process.Start("hl.exe", arguments: str);
            }
            else
            {
                string message = "Launch options not found. Please go into launch options and click double click Reset!!!";
                string title = "Launch options error";
                MessageBox.Show(message, title);
            }
        }
    }
}

options.cs

using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Windows.Forms;
using System.IO.Compression;

namespace WindowsFormsApp1
{
    public partial class Form4 : Form
    {
        private WebClient webClient = null;
        const string basPath = @"cstrike";

        public Form4()
        {
            InitializeComponent();
        }

        private void btnmdl_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                return;

            var mdldir = new DirectoryInfo(@"cstrike/models");
            string mdlzippath = $"{basPath}/models.zip";
            string extzippath = $"{basPath}";
            if (!mdldir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += MdlZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/models.zip"), $"{basPath}/models.zip");
            }
            else
            {
                foreach (FileInfo file in mdldir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in mdldir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += MdlZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/models.zip"), $"{basPath}/models.zip");
            }

        }

        private void MdlZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/models.zip", $"{basPath}");
            string mdlzippath = $"{basPath}/models.zip";

            if (File.Exists(mdlzippath))
            {
                File.Delete(mdlzippath);
            }
            else
            {
                //do nothing
            }

            string message = "Models are sucessfully restored!!!";
            string title = "Models restored";
            MessageBox.Show(message, title);
        }

        private void btnsound_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                return;

            var sounddir = new DirectoryInfo(@"cstrike/sound");
            string soundzippath = $"{basPath}/sound.zip";
            string extzippath = $"{basPath}";
            if (!sounddir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += SoundZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sound.zip"), $"{basPath}/sound.zip");
            }
            else
            {
                foreach (FileInfo file in sounddir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in sounddir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += SoundZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sound.zip"), $"{basPath}/sound.zip");
            }

        }

        private void SoundZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/sound.zip", $"{basPath}");
            string soundzippath = $"{basPath}/sound.zip";

            if (File.Exists(soundzippath))
            {
                File.Delete(soundzippath);
            }
            else
            {
                //do nothing
            }

            string message = "Sound are sucessfully restored!!!";
            string title = "Sound restored";
            MessageBox.Show(message, title);
        }

        private void btnspr_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                return;

            var sprdir = new DirectoryInfo(@"cstrike/sprites");
            string sprzippath = $"{basPath}/sprites.zip";
            string extzippath = $"{basPath}";
            if (!sprdir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += SprZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sprites.zip"), $"{basPath}/sprites.zip");
            }
            else
            {
                foreach (FileInfo file in sprdir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in sprdir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += SprZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/sprites.zip"), $"{basPath}/sprites.zip");
            }

        }

        private void SprZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/sprites.zip", $"{basPath}");
            string sprzippath = $"{basPath}/sprites.zip";

            if (File.Exists(sprzippath))
            {
                File.Delete(sprzippath);
            }
            else
            {
                //do nothing
            }

            string message = "Sprites are sucessfully restored!!!";
            string title = "Sprites restored";
            MessageBox.Show(message, title);
        }

        private void btndlls_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                    return;

            var dllsdir = new DirectoryInfo(@"cstrike/dlls");
            string dllzippath = $"{basPath}/dlls.zip";
            string extzippath = $"{basPath}";
            if (!dllsdir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += DllsZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/dlls.zip"), $"{basPath}/dlls.zip");
            }
            else
            {
                foreach (FileInfo file in dllsdir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in dllsdir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += DllsZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/dlls.zip"), $"{basPath}/dlls.zip");
            }

        }

        private void DllsZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/dlls.zip", $"{basPath}");
            string dllszippath = $"{basPath}/dlls.zip";

            if (File.Exists(dllszippath))
            {
                File.Delete(dllszippath);
            }
            else
            {
                //do nothing
            }

            string message = "Dlls are sucessfully restored!!!";
            string title = "Dlls restored";
            MessageBox.Show(message, title);
        }

        private void btngfx_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                    return;

            var gfxsdir = new DirectoryInfo(@"cstrike/gfx");
            string gfxzippath = $"{basPath}/gfx.zip";
            string extzippath = $"{basPath}";
            if (!gfxsdir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += GfxZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/gfx.zip"), $"{basPath}/gfx.zip");
            }
            else
            {
                foreach (FileInfo file in gfxsdir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in gfxsdir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += GfxZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/gfx.zip"), $"{basPath}/gfx.zip");
            }

        }

        private void GfxZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/gfx.zip", $"{basPath}");
            string gfxzippath = $"{basPath}/gfx.zip";

            if (File.Exists(gfxzippath))
            {
                File.Delete(gfxzippath);
            }
            else
            {
                //do nothing
            }

            string message = "Gfx are sucessfully restored!!!";
            string title = "Gfx restored";
            MessageBox.Show(message, title);
        }

        private void btnres_Click(object sender, EventArgs e)
        {
            // Is file downloading yet?
            if (webClient != null)
                return;

            var ressdir = new DirectoryInfo(@"cstrike/resource");
            string reszippath = $"{basPath}/resource.zip";
            string extzippath = $"{basPath}";
            if (!ressdir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += ResZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/resource.zip"), $"{basPath}/resource.zip");
            }
            else
            {
                foreach (FileInfo file in ressdir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in ressdir.GetDirectories())
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += ResZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/resource.zip"), $"{basPath}/resource.zip");
            }

        }

        private void ResZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/resource.zip", $"{basPath}");
            string reszippath = $"{basPath}/resource.zip";

            if (File.Exists(reszippath))
            {
                File.Delete(reszippath);
            }
            else
            {
                //do nothing
            }

            string message = "Resource are sucessfully restored!!!";
            string title = "Resource restored";
            MessageBox.Show(message, title);
        }

        private void btncfg_Click(object sender, EventArgs e)
        {
            string cfgpath = $"{basPath}/config.cfg";
            FileAttributes attributes = File.GetAttributes(cfgpath);

            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                // Make the file RW
                attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
                File.SetAttributes(cfgpath, attributes);
                Console.WriteLine("The {0} file is no longer RO.", cfgpath);
            }
            else
            {
                // Make the file RO
                File.SetAttributes(cfgpath, File.GetAttributes(cfgpath) | FileAttributes.ReadOnly);
                Console.WriteLine("The {0} file is now RO.", cfgpath);
            }
            // Is file downloading yet?
            if (webClient != null)
                return;

            var cfgsdir = new DirectoryInfo($"{basPath}");
            string cfgzippath = $"{basPath}/cfg.zip";
            string extzippath = $"{basPath}";
            if (!cfgsdir.Exists)
            {
                webClient = new WebClient();
                webClient.DownloadFileCompleted += CfgZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/cfg.zip"), $"{basPath}/cfg.zip");
            }
            else
            {
                foreach (FileInfo file in cfgsdir.GetFiles("*.cfg"))
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in cfgsdir.GetDirectories("*.cfg"))
                {
                    dir.Delete(true);
                }
                webClient = new WebClient();
                webClient.DownloadFileCompleted += CfgZipExtract;
                webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/csfiledownload/cfg.zip"), $"{basPath}/cfg.zip");
            }

        }

        private void CfgZipExtract(object sender, AsyncCompletedEventArgs e)
        {
            webClient = null;
            ZipFile.ExtractToDirectory($"{basPath}/cfg.zip", $"{basPath}");
            string cfgzippath = $"{basPath}/cfg.zip";
            string cfgpathh = $"{basPath}/config.cfg";

            if (File.Exists(cfgzippath))
            {
                File.Delete(cfgzippath);
            }
            else
            {
                //do nothing
            }

            File.SetAttributes(cfgpathh, File.GetAttributes(cfgpathh) | FileAttributes.ReadOnly);
            string message = "Configuration files are sucessfully restored!!!";
            string title = "Configuration files restored";
            MessageBox.Show(message, title);
        }
        private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
        {
            return attributes & ~attributesToRemove;
        }
    }
}

Заранее спасибо!

1 Ответ

0 голосов
/ 07 апреля 2020

Я найду ответ !!!

Я запустил его с правами администратора и все работает !! В любом случае, спасибо!

...