From 08ee40548ff71d86828c5eb2776e58c35140d581 Mon Sep 17 00:00:00 2001
From: grossmj <grossmj@gns3.net>
Date: Tue, 5 Dec 2023 21:24:40 +1000
Subject: [PATCH] Add custom executable paths on Windows

---
 gns3server/compute/base_node.py         | 3 +++
 gns3server/compute/dynamips/__init__.py | 3 +++
 gns3server/compute/vpcs/vpcs_vm.py      | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/gns3server/compute/base_node.py b/gns3server/compute/base_node.py
index a41a417a..639a5d41 100644
--- a/gns3server/compute/base_node.py
+++ b/gns3server/compute/base_node.py
@@ -656,6 +656,9 @@ class BaseNode:
         """
 
         path = self._manager.config.get_section_config("Server").get("ubridge_path", "ubridge")
+        if sys.platform.startswith("win") and hasattr(sys, "frozen"):
+            ubridge_dir = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "ubridge"))
+            os.environ["PATH"] = os.pathsep.join(ubridge_dir) + os.pathsep + os.environ.get("PATH", "")
         path = shutil.which(path)
         return path
 
diff --git a/gns3server/compute/dynamips/__init__.py b/gns3server/compute/dynamips/__init__.py
index c7287638..ce1d8722 100644
--- a/gns3server/compute/dynamips/__init__.py
+++ b/gns3server/compute/dynamips/__init__.py
@@ -252,6 +252,9 @@ class Dynamips(BaseManager):
         # look for Dynamips
         dynamips_path = self.config.get_section_config("Dynamips").get("dynamips_path", "dynamips")
         if not os.path.isabs(dynamips_path):
+            if sys.platform.startswith("win") and hasattr(sys, "frozen"):
+                dynamips_dir = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "dynamips"))
+                os.environ["PATH"] = os.pathsep.join(dynamips_dir) + os.pathsep + os.environ.get("PATH", "")
             dynamips_path = shutil.which(dynamips_path)
 
         if not dynamips_path:
diff --git a/gns3server/compute/vpcs/vpcs_vm.py b/gns3server/compute/vpcs/vpcs_vm.py
index 6fa29bf2..e5164df6 100644
--- a/gns3server/compute/vpcs/vpcs_vm.py
+++ b/gns3server/compute/vpcs/vpcs_vm.py
@@ -140,6 +140,9 @@ class VPCSVM(BaseNode):
 
         vpcs_path = self._manager.config.get_section_config("VPCS").get("vpcs_path", "vpcs")
         if not os.path.isabs(vpcs_path):
+            if sys.platform.startswith("win") and hasattr(sys, "frozen"):
+                vpcs_dir = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "vpcs"))
+                os.environ["PATH"] = os.pathsep.join(vpcs_dir) + os.pathsep + os.environ.get("PATH", "")
             vpcs_path = shutil.which(vpcs_path)
         return vpcs_path