gammasoft71 / xtd

Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications and libraries on Microsoft Windows, Apple macOS and Linux.
https://gammasoft71.github.io/xtd
MIT License
779 stars 59 forks source link

[BUG] Path not updated with xtd install on Windows #188

Closed jimorc closed 1 year ago

jimorc commented 2 years ago

Describe the bug

I installed Visual Studio Community 2022 and cmake. I then cloned the xtd repository and attempted to build it. The build ran for a long time, then produced the following output;

--snip--
 -- Up-to-date: C:/Program Files (x86)/xtd/share/xtd/themes/xtd_light/system-colors.css
  -- Up-to-date: C:/Program Files (x86)/xtd/share/xtd/themes/xtd_light/theme.css
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

1024 was unexpected at this time.

C:\Users\jimor\Projects\xtd>

I tried to build a simple app using;

xtdc build

but I get;

'xtdc' is not recognized as an internal or external command,
operable program or batch file.

To Reproduce

As described above.

Expected behaviour

xtd install to complete without errors and simple xtd based app to build.

Screenshots

N/A

Desktop (please complete the following information)

Additional context

none

Workaround

None known

gammasoft71 commented 2 years ago

Defect

This error is related to the calculation of the size of the path (added rexement) which returns an empty string instead of the size. So there is an error during the test. So the path is never updated. I still have to investigate. If there is no satisfactory solution, always ask the user to add the path manually as when the path exceeds 1024 characters.

Workaround

Add c:\Program Files\xtd\bin or c:\Program Files (x86)\xtd\bin (depends on where xtd is installed by your cmake version) to the user path manually.

gammasoft71 commented 2 years ago

Here is the problematic piece of code in install.cmd :

::______________________________________________________________________________
::                                                             Add xtdc-gui path
echo.%path%|findstr /C:"xtd\bin" >nul 2>&1
if not errorlevel 1 (
  echo The environment variable path already contains xtd.
) else (
  set new_path="%cmake_install_prefix%\xtd\bin;%path%"
  call :strlen new_path path_length
  if %path_length% LSS 1024 (
    setx path %new_path%
  ) else (
    echo.
    echo ---------------------------------------------------------------
    echo.
    echo WARNING : The path is greater than 1024.
    echo.
    echo setx will not work correctly with a path greater than 1024.
    echo Manually add "%cmake_install_prefix%\xtd\bin" in your path.
    echo.
    echo ---------------------------------------------------------------
    echo.
    pause
  )
)

::______________________________________________________________________________
::                                                               launch xtdc-gui
echo Launching xtdc-gui...
start "xtdc-gui" "%cmake_install_prefix%\xtd\bin\xtdc-gui.exe"

goto :eof

::______________________________________________________________________________
:: Gets the length of specified string.
:: param string_var The string to compute length.
:: param result_var That will cantains the length of the specified string.
:strlen  string_var  [result_var]
  setlocal EnableDelayedExpansion
  set "s=#!%~1!"
  set "len=0"
  for %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
    if "!s:~%%N,1!" neq "" (
      set /a "len+=%%N"
      set "s=!s:~%%N!"
    )
  )
  endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len%
exit /b

Error

Line 6 : get the length of new_path Line 7 : Test if new_length is less than 1024 -> error in the script because new_length is empty !

Remarks

The strlen "function" was found here : https://ss64.com/nt/syntax-strlen.html

gammasoft71 commented 1 year ago

I'm going to try to do it myself, finally.

gammasoft71 commented 1 year ago

I create a new tool set_path to add the xtd installation path to the user path.