Inno Setup error when installing to USB drive root: “You must enter a full path with drive letter”

梦想与她 提交于 2021-02-07 20:24:21

问题


I would like to know how to fix this kind of Error:

You must enter a full path with drive letter; for example: C:\APP or a UNC path in the form: \server\share

This appears whenever I try to force the Inno Setup Compiler (5.5.5 u) to put my stuff into, let say H:\ instead of H:\New Folder.

I need the compiler to customize my destination location to H:\.

Here is my sample program;

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={drive:F:}
AppendDefaultDirName=no

[Files]
Source: "File1.txt"; DestDir: "{code:GetExeLocation|{app}\My_Portable_App}"; \
  Flags: ignoreversion 
[Code]
var
  UsagePage: TInputOptionWizardPage;

procedure InitializeWizard;
begin
  { Create the pages }
  UsagePage := CreateInputOptionPage(wpWelcome,
    'Installation Type', 'Select Installation Option',
    'Where would you like to install this program',
    True, False);
  UsagePage.Add('Normal – PC Hard Disk Installation ');
  UsagePage.Add('Portable – USB Drive Installation');

  {Set Default – Normal Install}
  UsagePage.SelectedValueIndex := 0;
end;

var
  bIsPortable : Boolean;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  // If we have clicked the next button on our custom page.
  if (CurPageID = UsagePage.ID) then
  begin
    bIsPortable := not (UsagePage.SelectedValueIndex = 0);
  end;
  result := true; // need to return a value so next key has an impact
end;

function GetExeLocation (Param: String) : String;
begin
  if bIsPortable then
    result := Param
  else
    result := Param;
end;

function InstallType(sRequiredType:String):Boolean;
begin
  if sRequiredType = 'Portable' then
    result := bIsPortable
  else
    result := not bIsPortable;
end;

Explanation:

When I select "Normal – PC Hard Disk Installation", as my choice, all my installation files or folders should go to normal Path that is to C:\My Program, but when I select "Portable – USB Drive Installation" as my Entry, I would like to put all my installation files or folders directly into the USB Pen drive Root, that is in here H:\, where "H" is my USB Pen Drive letter which I have selected to put my stuff in. But my Program does not allow me to do so, instead it adds a New Folder by default to put my installation files or folders over there, that is to H:\New Folder which I do not need that at all!. And when I force to do what I want, it ends giving me an Error!

Please I need Your Help to fix this, and if this inno-setup can not do what I want, please point me another one, and I will be Thankful for that!

EDIT:

Let focus on the second choice that is "('portable – usb drive installation')" because that is my real target.

From the Source: I made some changes so that to make it more clear.

I added my destination Directory, that is {code:GetExeLocation|{app}\My_Portable_App}. So what I want here is that, all my installation files or folders to be installed inside this directory, I mean My_Portable_App. And the path to my USB pen drive should be H:\My_Portable_App. So when this goes fine, I want to see only This Folder My_Portable_App in my USB pen drive that will contain all my stuffs in there!!!

Thanks in advance!


回答1:


If you want to install directly into h:\ then you should explicitly enter that into the location box. If you also want to stop the My Program being appended after using the browse dialog then you need to ensure that AppendDefaultDirName is set to no.

Also note that for file2, the DestDir will end up being set to {app}/{app} if bIsPortable is true which will most likely expand to an invalid path.

Your best option is to use a {code:...} function to create a single "default" path based on bIsPortable and then everything can just install into {app} from there.




回答2:


I struggled with the validation too, where root was not valid in the TInputDirWizardPage. As it turns out there is a simple Inno Setup option that changes this behavior:

AllowRootDirectory=yes

will allow the user to specify a drive root without error. also see,

AllowUNCPath=yes/no

and

AllowNetworkDrive=yes/no

in the Inno help file for other validation modifiers that apply to the Select Destination Location Page.




回答3:


This setup file must be located on disc c:. That's all.



来源:https://stackoverflow.com/questions/26687212/inno-setup-error-when-installing-to-usb-drive-root-you-must-enter-a-full-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!