Exemplo n.º 1
0
        public void Unhide()
        {
            try
            {
                // The map ZIP file may exist in both the application data folder and the DLC folder.
                // Ensure hidden state is set for both!

                if (OverloadServerToolApplication.ValidFileName(LocalZipFileName, true) && LocalZipFileName.EndsWith(MapHiddenMarker))
                {
                    string newLocalZipFileName = LocalZipFileName.Replace(MapHiddenMarker, "");
                    File.Move(LocalZipFileName, newLocalZipFileName);
                    LocalZipFileName = newLocalZipFileName;
                }

                if (OverloadServerToolApplication.ValidFileName(LocalDLCZipFileName, true) && LocalDLCZipFileName.EndsWith(MapHiddenMarker))
                {
                    string newLocalDLCZipFileName = LocalDLCZipFileName.Replace(MapHiddenMarker, "");
                    File.Move(LocalDLCZipFileName, newLocalDLCZipFileName);
                    LocalDLCZipFileName = newLocalDLCZipFileName;
                }
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        public void DownloadAndInstallOlmod(OlmodRelease release, string localInstallFolder)
        {
            string localTempZip    = Path.GetTempFileName() + "_OST_Olmod_Update.zip";
            string localTempFolder = Path.GetTempFileName() + "_OST_Olmod_Update";

            Directory.CreateDirectory(localTempFolder);

            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => { return(true); };
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("User-Agent", "Overload Server Tool - user " + WindowsIdentity.GetCurrent().Name);
                    wc.DownloadFile(release.DownloadUrl, localTempZip);
                }

                ZipFile.ExtractToDirectory(localTempZip, localTempFolder);

                // Copy all files to destination, overwriting any existing files.
                DirectoryInfo dir = new DirectoryInfo(localTempFolder);
                foreach (FileInfo fi in dir.GetFiles())
                {
                    File.Copy(fi.FullName, Path.Combine(localInstallFolder, fi.Name), true);
                }

                // Time stamp olmod.exe.
                File.SetCreationTime(Path.Combine(localInstallFolder, "olmod.exe"), release.Created);
                File.SetLastWriteTime(Path.Combine(localInstallFolder, "olmod.exe"), release.Created);

                LogMessage(String.Format($"Olmod has been updated to release {release.Version}"));
            }
            catch (Exception ex)
            {
                LogErrorMessage(String.Format($"Cannot download Olmod ZIP file from Github: {ex.Message}"));
            }
            finally
            {
                if (OverloadServerToolApplication.ValidFileName(localTempZip, true))
                {
                    try { File.Delete(localTempZip); } catch { }
                }
                if (OverloadServerToolApplication.ValidDirectoryName(localTempFolder, true))
                {
                    try { OverloadServerToolApplication.RemoveDirectory(localTempFolder); } catch { }
                }
            }
        }
Exemplo n.º 3
0
        public void FindOverloadInstall(bool onlyOverload = false)
        {
            LogDebugMessage("FindOverloadInstall()");

            bool found = false;

            try
            {
                found = new FileInfo(OverloadPath).Exists;
            }
            catch
            {
            }

            if (!found)
            {
                string steamLocation = null;
                string gogLocation   = null;
                string dvdLocation   = null;

                // Check for a STEAM install of Overload.
                logger?.ErrorLogMessage(String.Format($"Checking for STEAM registry key."));

                try
                {
                    using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                    {
                        using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 448850"))
                        {
                            if (key != null)
                            {
                                try
                                {
                                    steamLocation = (string)key.GetValue("InstallLocation");
                                    string steamOverloadName = Path.Combine(steamLocation, "overload.exe");
                                    if (!File.Exists(Path.Combine(steamLocation, "overload.exe")))
                                    {
                                        steamLocation = null;
                                    }
                                }
                                catch
                                {
                                    steamLocation = null;
                                }

                                if (String.IsNullOrEmpty(steamLocation))
                                {
                                    try
                                    {
                                        steamLocation = (string)key.GetValue("UninstallString");
                                        if (!String.IsNullOrEmpty(steamLocation))
                                        {
                                            string[] parts = steamLocation.Split("\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                            if (parts.Length > 1)
                                            {
                                                steamLocation = Path.Combine(Path.GetDirectoryName(parts[0]), @"steamapps\common\Overload");
                                            }
                                            else
                                            {
                                                steamLocation = null;
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        steamLocation = null;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //logger?.ErrorLogMessage(String.Format($"Exception while checking STEAM registry key: {ex.Message}"));
                }

                // Check for a GOG install of Overload.
                logger?.ErrorLogMessage(String.Format($"Checking for GOG registry key."));

                try
                {
                    using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                    {
                        using (var key = hklm.OpenSubKey(@"SOFTWARE\WOW6432Node\GOG.com\Games\1309632191"))
                        {
                            if (key != null)
                            {
                                gogLocation = (string)key.GetValue("Path");
                            }
                            if (!String.IsNullOrEmpty(gogLocation))
                            {
                                if (!File.Exists(Path.Combine(gogLocation, "overload.exe")))
                                {
                                    gogLocation = null;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //logger?.ErrorLogMessage(String.Format($"Exception while checking GOG registry key: {ex.Message}"));
                }

                // Check for a DVD install of Overload (KickStarter backer DVD).
                logger?.ErrorLogMessage(String.Format($"Checking for DVD registry key."));
                try
                {
                    using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                    {
                        using (var key = hklm.OpenSubKey(@"SOFTWARE\WOW6432Node\Revival Productions, LLC\Overload"))
                        {
                            if (key != null)
                            {
                                dvdLocation = (string)key.GetValue("Path");
                            }
                            if (!String.IsNullOrEmpty(dvdLocation))
                            {
                                if (!File.Exists(Path.Combine(dvdLocation, "overload.exe")))
                                {
                                    dvdLocation = null;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //logger?.ErrorLogMessage(String.Format($"Exception while checking DVD registry key: {ex.Message}"));
                }

                initPath = steamLocation ?? gogLocation ?? dvdLocation;

                if (String.IsNullOrEmpty(initPath))
                {
                    logger?.ErrorLogMessage(String.Format($"Unable to autolocate Overload installation!"));
                    initPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                }

                string overloadFileName = Path.Combine(initPath, "overload.exe");
                string olproxyFileName  = Path.Combine(initPath, "olproxy.exe");

                OverloadPath = overloadFileName;

                // Set Olproxy path.
                if (!onlyOverload)
                {
                    OlproxyPath = olproxyFileName;
                }
            }

            // Set Olmod.exe path to Overload installation folder if not found.
            if (String.IsNullOrEmpty(OlmodPath) || !OverloadServerToolApplication.ValidFileName(OlmodPath))
            {
                OlmodPath = Path.Combine(initPath, "olmod.exe");
                if (OverloadServerToolApplication.ValidFileName(OlmodPath))
                {
                    OlmodPath = Path.Combine(Path.GetDirectoryName(OverloadPath), "olmod.exe");
                }
            }
            else
            {
                try
                {
                    string test = Path.Combine(Path.GetDirectoryName(OverloadPath), "olmod.exe");
                    if (new FileInfo(test).Exists)
                    {
                        OlmodPath = test;
                    }
                }
                catch
                {
                }
            }

            OverloadExecutable.Text = OverloadPath;
            OlproxyExecutable.Text  = OlproxyPath;
            OlmodExecutable.Text    = OlmodPath;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update a single Overload map.
        /// </summary>
        /// <param name="map">The map to update.</param>
        /// <returns></returns>
        public async Task <bool> UpdateMap(OverloadMap map, bool forceUpdate)
        {
            Checked++;

            if (String.IsNullOrEmpty(map.Url))
            {
                return(false);
            }

            string mapZipName        = map.ZipName;
            string mapDirectoryPath  = (String.IsNullOrEmpty(dlcMapFolder) || !SaveNewMapsToDLCFolder) ? applicationMapFolder : dlcMapFolder;
            string mapZipFilePath    = WebUtility.UrlDecode(Path.Combine(mapDirectoryPath, mapZipName));
            string mapZipDisplayName = WebUtility.UrlDecode(mapZipName).Trim();

            // Check if we should use existing download path.
            if (map.InDLCFolder)
            {
                mapDirectoryPath = Path.GetDirectoryName(map.LocalDLCZipFileName);
                mapZipFilePath   = map.LocalDLCZipFileName;
            }
            else if (map.InApplicationDataFolder)
            {
                mapDirectoryPath = Path.GetDirectoryName(map.LocalZipFileName);
                mapZipFilePath   = map.LocalZipFileName;
            }

            // Create (DLC or application data) directory if it doesn't exist.
            if (!Directory.Exists(mapDirectoryPath))
            {
                Directory.CreateDirectory(mapDirectoryPath);
            }

            // Don't update hidden maps.
            if (File.Exists(mapZipFilePath + HiddenMarker))
            {
                return(false);
            }

            // Check for new map file.
            if (!forceUpdate && OverloadServerToolApplication.ValidFileName(mapZipFilePath))
            {
                if (File.Exists(mapZipFilePath))
                {
                    // Map already downloaded. Compare date and size against online version.
                    FileInfo fi = new FileInfo(mapZipFilePath);
                    if ((fi.Length == map.Size) && (fi.LastWriteTime == map.DateTime))
                    {
                        return(false);
                    }
                }
                else
                {
                    // Only update existing maps?
                    if (OnlyUpdateExistingMaps)
                    {
                        return(false);
                    }
                }
            }

            try
            {
                bool existingFile = File.Exists(mapZipFilePath);

                // Download map.
                DownloadResult result = await DownloadMapFile(map, new Uri(map.Url), mapZipFilePath, mapZipDisplayName);

                if (result.Exception != null)
                {
                    throw result.Exception;
                }
                if (result.Succes == false)
                {
                    if (String.IsNullOrEmpty(result.Message))
                    {
                        result.Message = String.Format($"Unable to download {mapZipDisplayName}");
                    }
                    try { File.Delete(mapZipFilePath); } catch { }
                    throw new Exception(String.Format($"Unable to download {result.Message }"));
                }

                // LogMessage(String.Format($"Downloading map {mapZipDisplayName}."));

                if (existingFile)
                {
                    Updated++;
                }
                else
                {
                    Created++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                Errors++;

                LogErrorMessage(String.Format($"Error downloading {mapZipDisplayName}: {ex.Message}"));
                return(false);
            }
        }