From 68e360b5c6270081c5a425cb439a8298dbe8eafe Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Mon, 11 Sep 2023 15:42:10 -0400
Subject: [PATCH] show warning if insufficient memory

---
 .../org/sleuthkit/autopsy/core/Installer.java | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/Core/src/org/sleuthkit/autopsy/core/Installer.java b/Core/src/org/sleuthkit/autopsy/core/Installer.java
index 24c40e9967..662759f800 100644
--- a/Core/src/org/sleuthkit/autopsy/core/Installer.java
+++ b/Core/src/org/sleuthkit/autopsy/core/Installer.java
@@ -20,8 +20,10 @@
 
 import com.sun.jna.platform.win32.Kernel32;
 import java.awt.Cursor;
+import java.awt.GraphicsEnvironment;
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -34,6 +36,7 @@
 import javafx.application.Platform;
 import javafx.embed.swing.JFXPanel;
 import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
 import net.sf.sevenzipjbinding.SevenZip;
 import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
 import org.apache.commons.io.FileUtils;
@@ -41,6 +44,7 @@
 import org.openide.modules.InstalledFileLocator;
 import org.openide.modules.ModuleInstall;
 import org.openide.util.NbBundle;
+import org.openide.util.NbBundle.Messages;
 import org.openide.windows.WindowManager;
 import org.sleuthkit.autopsy.actions.IngestRunningCheck;
 import org.sleuthkit.autopsy.casemodule.Case;
@@ -373,6 +377,7 @@ private static void ensureOcrLanguagePacksFolderExists() {
     @Override
     public void restored() {
         super.restored();
+        checkMemoryAvailable();
         ensurePythonModulesFolderExists();
         ensureClassifierFolderExists();
         ensureOcrLanguagePacksFolderExists();
@@ -392,6 +397,48 @@ public void restored() {
         preloadTranslationServices();
     }
 
+    /**
+     * Checks system resources logging any potential issues.
+     */
+    @Messages({
+        "Installer_checkMemoryAvailable_physicalRamExpected_title=System Does Not Meet Requirements",
+        "# {0} - physicalMemory",
+        "Installer_checkMemoryAvailable_physicalRamExpected_desc=Physical memory: {0}, is less than the 8GB required.  Some aspects of the application may not work as expected.",
+        "Installer_checkMemoryAvailable_maxMemExpected_title=System Does Not Meet Requirements",
+        "# {0} - maxMemory",
+        "Installer_checkMemoryAvailable_maxMemExpected_desc=Maximum JVM memory: {0}, is less than the 2GB required.  Some aspects of the application may not work as expected."
+    })
+    private void checkMemoryAvailable() {
+        long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory
+                .getOperatingSystemMXBean()).getTotalMemorySize();
+        if (memorySize < 8_000_000) {
+            String desc = Bundle.Installer_checkMemoryAvailable_physicalRamExpected_desc(FileUtils.byteCountToDisplaySize(memorySize));
+
+            logger.log(Level.SEVERE, desc);
+            if (!GraphicsEnvironment.isHeadless() && RuntimeProperties.runningWithGUI()) {
+                JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
+                        "<html>" + desc + "</html>",
+                        Bundle.Installer_checkMemoryAvailable_physicalRamExpected_title(),
+                        JOptionPane.WARNING_MESSAGE);
+            }
+            return;
+        }
+
+        long maxMemory = Runtime.getRuntime().maxMemory();
+        if (maxMemory < 2_000_000) {
+            String desc = Bundle.Installer_checkMemoryAvailable_maxMemExpected_desc(FileUtils.byteCountToDisplaySize(maxMemory));
+
+            logger.log(Level.SEVERE, desc);
+            if (!GraphicsEnvironment.isHeadless() && RuntimeProperties.runningWithGUI()) {
+                JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
+                        "<html>" + desc + "</html>",
+                        Bundle.Installer_checkMemoryAvailable_maxMemExpected_title(),
+                        JOptionPane.WARNING_MESSAGE);
+            }
+            return;
+        }
+    }
+
     /**
      * Initializes 7zip-java bindings. We are performing initialization once
      * because we encountered issues related to file locking when initialization
-- 
GitLab