Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access deni when autoupdate and unzip #639

Open
huuthanh89 opened this issue Sep 7, 2023 · 4 comments
Open

Access deni when autoupdate and unzip #639

huuthanh89 opened this issue Sep 7, 2023 · 4 comments

Comments

@huuthanh89
Copy link

huuthanh89 commented Sep 7, 2023

After download update file (zip), it cannot run unzip
https://i.imgur.com/QUL9Ydq.png
image

Some files on this folder (htkk) is Read-only, however overwrite it?
(if i manual download and using winrar to extract same folder, it's ok).

Thank you!

@ravibpatel
Copy link
Owner

It is possible to change file attributes and replace files if the user running the app have proper permissions. It is possible that WinRAR does the same. I will look into it and let you know. Thanks for reporting it.

@huuthanh89
Copy link
Author

If you have solution, please let me know.
Thank you!

@ravibpatel
Copy link
Owner

Right now, you can remove the read Only attribute in Application Exit event as shown below.

AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;

private void AutoUpdater_ApplicationExitEvent()
{
	string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
	RemoveReadOnlyAttribute(currentDirectory);
}


private void RemoveReadOnlyAttribute(string directoryPath)
{
	// Remove readonly attribute from files in the current directory
	string[] files = Directory.GetFiles(directoryPath);
	foreach (string file in files)
	{
		FileAttributes attributes = File.GetAttributes(file);
		if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
		{
			File.SetAttributes(file, attributes & ~FileAttributes.ReadOnly);
		}
	}

	// Recursively remove readonly attribute from subdirectories
	string[] subdirectories = Directory.GetDirectories(directoryPath);
	foreach (string subdirectory in subdirectories)
	{
		RemoveReadOnlyAttribute(subdirectory);
	}
}

@huuthanh89
Copy link
Author

Ok thank you, i will try it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants