Nexus-Mods / Nexus-Mod-Manager

GNU General Public License v2.0
991 stars 165 forks source link

Fake no perrmission (reg path parse bug) #1143

Open Bxaa opened 3 years ago

Bxaa commented 3 years ago

123

i don't know is it a correct reason of issue... If nmm priority get path from reg - maybe add: regpath.replace("\\", "\") or New FileInfo(regpath + Path.DirectorySeparatorChar).DirectoryName (This is valid reg entry for Fallout 3 gog and in some case it contains two directory separators chars) I have all perrmission to this folders (NMM with fallout NV work fine in same dir)

EDIT: Yep, i change reg entry (remove dupl 'slashes') and now it work You should add regpath.replace("\\", "\") or New FileInfo(regpath + Path.DirectorySeparatorChar).DirectoryName to your code, if nmm take path from reg This is a best solution: New FileInfo(regpath + Path.DirectorySeparatorChar).DirectoryName I dont use c#, but i hope i wrote correct

UPD: NOTICE: gog installer make a path for NV like 'D:\Games\fallout new vegas/' Use FileInfo - it resolve all such variants with any games and you'll get a correct path for system.io THX

DuskDweller commented 3 years ago

Thanks for the feedback! I'll add this to the next release.

DuskDweller commented 3 years ago

I'm unable to replicate your issue, also NMM doesn't retrieve those paths from the Windows registry when they're already set in the NMM's config files, so changing it wouldn't matter. Do you have a way to consistently replicate it ?

Bxaa commented 3 years ago

NMM doesn't retrieve those paths from the Windows registry ?

1 2

I installed current version nmm and got this issue Then, i just change path in reg to d:\games\Fallout 3 and then (run game rescan and by pressing red cross update path without new search ) it fixed issue Look carefully at your source codes :)

Tip: Also add check for game real path exist (is it equal to reg path) to exclude such mistakes NMM found Fallout 3 at D:\\Games\\Fallout 3? Or it just found regentry? :) and use FileInfo(String_Regpath + Path.DirectorySeparatorChar).DirectoryName to normalize path (if it contains some addition separators depend on OS system settings)

For test:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\bethesda softworks\fallout3]
"Installed Path"="D:\\\\Games\\\\Fallout 3"

Thx for nmm and sorry my english

DuskDweller commented 3 years ago

That's why I pointed out "when they're already set in the NMM's config files", you didn't specify you rescanned after changing the reg. Of course if you rescan it then it will try to retrieve it from the registry, and set it again in the config files, and NMM will use that setting it won't go each time in the registry.

Anyway I tried replicating your issue with either single, double, quadruple, slash or backslash, and it kept working.

Bxaa commented 3 years ago

_Anyway I tried replicating your issue with either single, double, quadruple, slash or backslash, and it kept working._ Keep working? What are you mean? You have installed fallout 3 and reg entry with \\ and no perrmission error? Your path look like? 1 NMM just not launch in my case, if i try select fallout 3 in nmm menu (it throw perrmission...)

Ok...anyway after correcting reg path to single slash all fine and it launch without issues

Bxaa commented 3 years ago
public class GameDiscoverer
---\\---\\---
// ADDED  FileInfo
var installationPath = new FileInfo(gameModeFactory.GameModeDescriptor.InstallationPath + 
Path.DirectorySeparatorChar).DirectoryName;
Trace.TraceInformation("Returned: {0} (IsNull={1})", installationPath, string.IsNullOrEmpty(installationPath));
Trace.Unindent();
if (Verify(gameModeFactory.GameModeDescriptor.ModeId, installationPath))
    FoundCandidate(gameModeFactory.GameModeDescriptor, installationPath);
Trace.TraceInformation("Asking Game Mode...");
Trace.Indent();
installationPath = new FileInfo(gameModeFactory.GetInstallationPath() + Path.DirectorySeparatorChar).DirectoryName;
--\\--\\--
protected void FoundCandidate(IGameModeDescriptor gameMode, string installationPath)
--\\--\\--

FileUtil.NormalizePath - very bad!
1) Never use .ToString() for os depended special chars!  Also in most cases you should use -->  .ToString(CultureInfo.InvariantCulture) or CSTR

public static string NormalizePath(string p_strPath) 
        {
private static readonly Regex m_rgxCleanPath = new Regex("[" + Path.DirectorySeparatorChar + Path.AltDirectorySeparatorChar + "]{2,}"); ---- 1) NO NEED TO USE REGEX (Also this function is not correct)!
\\ --  REMOVE THIS!   string strNormalizedPath = m_rgxCleanPath.Replace(p_strPath, Path.DirectorySeparatorChar.ToString());
            \\  -- REMOVE THIS!  strNormalizedPath = strNormalizedPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            \\  --  REMOVE THIS! Use [trimend] only (some long path prefixes if you use it startwith \\?\ or  \\\\?\\)  strNormalizedPath = strNormalizedPath.Trim(Path.DirectorySeparatorChar);
            \\  --  REMOVE THIS!  return strNormalizedPath;
              return new FileInfo(p_strPath + Path.DirectorySeparatorChar).DirectoryName; \\ --  USE IT INSTED ALL OF THIS!
                   }

You should check all your functions that use m_rgxCleanPath and NormalizePath (or similar)

123

DuskDweller commented 3 years ago

Which OS is installed on your system ?

Bxaa commented 3 years ago

Win 10 x64 enterprise (russian) (long path policy enabled)