<commit_before>﻿using System;
using Microsoft.Win32;

namespace FreenetTray {
    public enum JREType {
        None,
        JRE64Bit,
        JRE32Bit,
    }

    public class MissingJRE: Exception { }

    public class MachineConfig {

        private static string JRERegistryKey = @"Software\\JavaSoft\\Java Runtime Environment";
        private static string JRE10RegistryKey = @"Software\\JavaSoft\\JRE";

        private static bool Has64BitJRE {
            get {
                RegistryKey local64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                RegistryKey jreKey64 = local64.OpenSubKey(JRERegistryKey);
                RegistryKey jreKey6410 = local64.OpenSubKey(JRE10RegistryKey);
                if (jreKey64 != null || jreKey6410 != null) {
                    return true;
                }
                return false;
            }
        }

        private static bool Has32BitJRE {
            get {
                RegistryKey local32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                RegistryKey jreKey32 = local32.OpenSubKey(JRERegistryKey);
                if (jreKey32 != null) {
                    return true;
                }
                return false;
            }
        }

        // find the best available JRE
        public static JREType GetBestAvailableJRE {
            get {
                if (Environment.Is64BitOperatingSystem) {
                    // if we're on a 64-bit OS and have a 64-bit JRE we want to use it
                    if (Has64BitJRE) {
                        FNLog.Debug("64-bit JRE found");
                        return JREType.JRE64Bit;
                    }
                }

                // if we're on 32-bit OS or no 64-bit JRE was found, we have no other choice
                // but to try the 32-bit JRE
                if (Has32BitJRE) {
                    FNLog.Debug("32-bit JRE found");

                    return JREType.JRE32Bit;
                }

                // no JRE found, this could happen in practice if the only available JRE was uninstalled
                FNLog.Debug("No JRE found");

                return JREType.None;
            }
        }
    }
}
<commit_msg>always set the Java CurrentVersion and JavaHome registry key for the old key to enable the wrapper to find Java<commit_after>﻿using System;
using Microsoft.Win32;

namespace FreenetTray {
    public enum JREType {
        None,
        JRE64Bit,
        JRE32Bit,
    }

    public class MissingJRE: Exception { }

    public class MachineConfig {

        private static string JRERegistryKey = @"Software\\JavaSoft\\Java Runtime Environment";
        private static string JRE10RegistryKey = @"Software\\JavaSoft\\JRE";

        private static bool Has64BitJRE {
            get {
                RegistryKey local64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                RegistryKey jreKey64 = local64.OpenSubKey(JRERegistryKey);
                RegistryKey jreKey6410 = local64.OpenSubKey(JRE10RegistryKey);
                if (jreKey64 != null && jreKey64.GetValue(@"FakeKeyForFreenet") != true) {
                    return true;
                }
                if (jreKey6410 != null) {
                    // create old style registry key to get the wrapper to work
                    jreKey64 = local64.CreateSubKey(JRERegistryKey);
                    // to distinguish from real entry, so we can keep it up to date over external Java updates (see above)
                    jreKey64.SetValue(@"FakeKeyForFreenet", true);
                    jreKey64.SetValue(@"CurrentVersion",jreKey6410.GetValue(@"CurrentVersion") );
                    RegistryKey jreKey64ForVersion = jreKey64.CreateSubKey(jreKey6410.GetValue(@"CurrentVersion"));
                    jreKey64ForVersion.SetValue(@"JavaHome",
                                                jreKey6410.OpenSubKey(jreKey6410.GetValue(@"CurrentVersion")).GetValue(@"JavaHome"));
                    return true;
                }
                return false;
            }
        }

        private static bool Has32BitJRE {
            get {
                RegistryKey local32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                RegistryKey jreKey32 = local32.OpenSubKey(JRERegistryKey);
                if (jreKey32 != null) {
                    return true;
                }
                return false;
            }
        }

        // find the best available JRE
        public static JREType GetBestAvailableJRE {
            get {
                if (Environment.Is64BitOperatingSystem) {
                    // if we're on a 64-bit OS and have a 64-bit JRE we want to use it
                    if (Has64BitJRE) {
                        FNLog.Debug("64-bit JRE found");
                        return JREType.JRE64Bit;
                    }
                }

                // if we're on 32-bit OS or no 64-bit JRE was found, we have no other choice
                // but to try the 32-bit JRE
                if (Has32BitJRE) {
                    FNLog.Debug("32-bit JRE found");

                    return JREType.JRE32Bit;
                }

                // no JRE found, this could happen in practice if the only available JRE was uninstalled
                FNLog.Debug("No JRE found");

                return JREType.None;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.07210316018888485, 'fraction_numerical': 0.030512168543407193, 'mean_word_length': 1.465085049239033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '715457', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1389, 'n_words': 380}