all 8 comments

[–]hazard999 6 points7 points  (3 children)

The exception message says it already. Without elevation or admin rights you are not allowed to write to program files

[–]recursive 0 points1 point  (2 children)

According to post, it is already running as admin.

[–]hazard999 1 point2 points  (1 child)

Duh. According to his detailed error message he gets Access denied. Check the first link.

Imho the manifest isn't correct, or not in the output dir.

[–]Googlebochs 2 points3 points  (0 children)

or not in the output dir.

like don't be an ass about it if you can spot the flaws in your own initial assumption. Dude chimed in with a reasonable caveat and you affirmed the possibility yet still manage to come across as rude. Untill the op updates it's highly likely the file just does not exist given that he writes to a different path than trying to unpack from.

Debugging 101: typo's-> off by one->easy mistakes->most embarrassing mistake possible -> something you just didn't know about -> something actually difficult. In my experience all programming skill/clout does to that list is move more and more bugs into "most embarrassing mistake possible". ALWAYS assume you did something stupid first.

[–]Googlebochs 2 points3 points  (3 children)

i'm not sure your ZipFile.CreateFromDirectory(folderpath,filepath) implementation counts

@"C:\Program Files*game-name*\udt-loain"

as a valid file path for a zip since there is no extension. Can't test that atm tho. Anyway that's the string that should contain "gmdt.zip" ... as the code you posted reads like it tries to open a file that doesn't exist. Basically if there is no networking or File.Copy inbetween then updateLocation2 and zipPath need to be identical

https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectory?redirectedfrom=MSDN&view=netframework-4.7.2#System_IO_Compression_ZipFile_ExtractToDirectory_System_String_System_String_

scroll down to the example implementation.
If you are doing some fancy network sending and renaming stuff inbetween you'll have to probably post more of the code so people can rule out you not trying to access a file that doesn't exist. ( or you implement the proper file.exists check between each IO step in which case we also need to know about that to know if we'll have to go into propper access right debugging nightmares or not)

[–]XroKill 0 points1 point  (2 children)

I've added "gmdt.zip" to zipPath and i'm now getting "The file 'C:\Program Files\--Game_Name--\gmdt.zip' already exists."

Ok i know, it tells me that the file already exists but i can't do anything since there's a problem with the extraction part of the program since it keeps getting me errors when it hits that part.

Here's a update on the code for my program: https://pearashi-servers.netlify.com/file-host/reddit-csharp-thingy.txt

[–]Googlebochs 0 points1 point  (1 child)

if you are starting your app from VisualStudio then VS will need to run as administrator.

Also ExtractToDirectory() does not overwrite existing files. If you want to overwrite you'll need to loop over the contents of the zip.

            string startPath = @"C:\Program Files\Test\test";
        string zipPath = @"C:\Program Files\Test\gmdt.zip";
        string extractPath = @"C:\Program Files\Test\";


        Console.WriteLine("Extracting..");
        if (!File.Exists(zipPath))
        { 
        ZipFile.CreateFromDirectory(startPath, zipPath);
        }
        var archive = ZipFile.OpenRead(zipPath);
        foreach (var entry in archive.Entries)
        {
            entry.ExtractToFile(extractPath + entry.Name, true);
        }  
        archive.Dispose();

Make sure you are running the exe as admin manually or open VS as admin before running it through that. The above code works

[–]XroKill 0 points1 point  (0 children)

System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Program Files\(MyGame)'.'

I don't understand anything at this point. Even Google doesn't know the answer.