예제 #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
            {
            }
        }
예제 #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 { }
                }
            }
        }
예제 #3
0
파일: Updating.cs 프로젝트: maestrodk/OST
        public void UpdateCheck(string debugFileName, bool forceUpdate = false)
        {
            try
            {
                OverloadServerToolApplication.LogDebugMessage("Checking for new OST release.", debugFileName);

                OSTRelease release = GetLastestRelease;
                if (release != null)
                {
                    OverloadServerToolApplication.LogDebugMessage("Got release info - checking version.", debugFileName);

                    // Fix version numbers so they are both in xx.yy.zz format (3 components and numbers only).
                    string newVersion = OverloadServerToolApplication.VersionStringFix(release.Version);

                    string currentVersion = null;
                    using (var process = Process.GetCurrentProcess()) currentVersion = OverloadServerToolApplication.GetFileVersion(process.MainModule.FileName);
                    string[] currentVersionSplit = currentVersion.Split(".".ToCharArray());
                    if (currentVersionSplit.Length > 3)
                    {
                        currentVersion = currentVersionSplit[0] + "." + currentVersionSplit[1] + "." + currentVersionSplit[2];
                    }

                    // Check if update is available.
                    if (forceUpdate || (!String.IsNullOrEmpty(currentVersion) && (currentVersion != newVersion)))
                    {
                        PerformUpdate(release, currentVersion, newVersion, Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory));
                    }
                    else
                    {
                        OverloadServerToolApplication.LogDebugMessage(String.Format($"No update available - continuing OST startup.", debugFileName));
                    }
                }
                else
                {
                    OverloadServerToolApplication.LogDebugMessage("Unable to get OST release info.", debugFileName);
                }
            }
            catch (Exception ex)
            {
                OverloadServerToolApplication.LogDebugMessage(String.Format($"Unable to check/perform OST update: {ex.Message}"), debugFileName);
            }
        }
예제 #4
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;
        }
예제 #5
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);
            }
        }
예제 #6
0
        /// <summary>
        /// Updates both online maps available for download as well as local maps.
        /// </summary>
        /// <param name="mapListUrl">URL to online JSON master map list.</param>
        /// <param name="dlcMaps">Path to local DLC folder (or null).</param>
        /// <param name="applicationMaps">Path to local application folder (or null).</param>
        public void UpdateMapList(string mapListUrl = null, string dlcMaps = null, string applicationMaps = null)
        {
            // Check for override of default URL to JSON map list.
            if (String.IsNullOrEmpty(mapListUrl))
            {
                mapListUrl = DefaultOnlineMapListUrl;
            }

            // Check DLC/application directory names.
            if (!String.IsNullOrEmpty(dlcMaps))
            {
                dlcMapFolder = dlcMaps;

                if (!OverloadServerToolApplication.ValidDirectoryName(dlcMapFolder))
                {
                    LogErrorMessage("DLC directory name is invalid!");
                    return;
                }
            }

            if (!String.IsNullOrEmpty(applicationMaps))
            {
                applicationMapFolder = applicationMaps;

                if (!OverloadServerToolApplication.ValidDirectoryName(applicationMapFolder))
                {
                    LogErrorMessage("Application data directory name is invalid!");
                    return;
                }
            }

            // Need at least one defined folder to store maps.
            if (String.IsNullOrEmpty(applicationMapFolder) && String.IsNullOrEmpty(dlcMapFolder))
            {
                LogErrorMessage("No application data directory or DLC directory found!");
                return;
            }

            // Collect all new online and local maps.
            SortedList <string, OverloadMap> newMapList = new SortedList <String, OverloadMap>();

            // First find all online maps.
            try
            {
                // Get URL base so we can construct full URLs to the online map ZIP files.
                Uri    uri     = new Uri(mapListUrl);
                string baseUrl = String.Concat(uri.Scheme, Uri.SchemeDelimiter, uri.Host);

                // Get map list and build internal map master list.
                string  jsonMapList = new WebClient().DownloadString(mapListUrl);
                dynamic mapList     = JsonConvert.DeserializeObject(jsonMapList);
                foreach (var map in mapList)
                {
                    // Check to make sure it is a ZIP file before adding it to the list.
                    string mapUrl = baseUrl + map.url;
                    Uri    mapUri = new Uri(mapUrl);
                    if (mapUri.Segments.Length > 2)
                    {
                        // Get the ZIP file name from URL.
                        string mapZipName = mapUri.Segments[mapUri.Segments.Length - 1];
                        if (mapZipName.ToLower().EndsWith(".zip"))
                        {
                            // Uppercase first char in map name.
                            mapZipName = mapZipName.Substring(0, 1).ToUpper() + mapZipName.Substring(1);

                            OverloadMap newMap = new OverloadMap(baseUrl + map.url, UnixTimeStampToDateTime(Convert.ToDouble(map.mtime)), Convert.ToInt32(map.size), mapZipName);
                            newMapList.Add(mapZipName.ToLower(), newMap);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogErrorMessage(String.Format($"Unable to get online map list: {ex.Message}"));
            }

            // Now add any local maps or update info if existing local map file exists.
            if (OverloadServerToolApplication.ValidDirectoryName(applicationMapFolder))
            {
                try
                {
                    Directory.CreateDirectory(applicationMapFolder);

                    string[] list = Directory.GetFiles(applicationMapFolder, "*.zip*");
                    foreach (string mapFileName in list)
                    {
                        if (mapFileName.EndsWith(HiddenMarker) || mapFileName.ToLower().EndsWith(".zip"))
                        {
                            string mapKey = Path.GetFileName(mapFileName).ToLower();

                            FileInfo    fiLocalMap = new FileInfo(mapFileName);
                            OverloadMap newMap     = new OverloadMap(null, UnixTimeStampToDateTime(0), Convert.ToInt32(fiLocalMap.Length), mapFileName);

                            bool found = false;
                            foreach (KeyValuePair <string, OverloadMap> map in newMapList)
                            {
                                if (newMap.SameZipFileName(map.Value))
                                {
                                    // We found a local map that matches the ZIP filename as found online.
                                    found = true;

                                    // Uppercase first char in map name and remove hidden marker if present.
                                    string mapZipName = fiLocalMap.Name;
                                    mapZipName        = mapZipName.Substring(0, 1).ToUpper() + mapZipName.Substring(1);
                                    mapZipName        = mapZipName.Replace(HiddenMarker, "");
                                    map.Value.ZipName = mapZipName;

                                    // Save full path to ZIP file in the application data folder.
                                    map.Value.LocalZipFileName = fiLocalMap.FullName;
                                }
                            }

                            if (!found)
                            {
                                newMapList.Add(mapFileName.ToLower(), newMap);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogErrorMessage(String.Format($"Unable to get local maps: {ex.Message}"));
                }
            }

            if (OverloadServerToolApplication.ValidDirectoryName(dlcMapFolder))
            {
                try
                {
                    Directory.CreateDirectory(dlcMapFolder);

                    string[] list = Directory.GetFiles(dlcMapFolder, "*.zip*");
                    foreach (string mapFileName in list)
                    {
                        if (mapFileName.EndsWith(HiddenMarker) || mapFileName.ToLower().EndsWith(".zip"))
                        {
                            string      mapKey     = Path.GetFileName(mapFileName).ToLower();
                            FileInfo    fiLocalMap = new FileInfo(mapFileName);
                            OverloadMap newMap     = new OverloadMap(null, UnixTimeStampToDateTime(0), Convert.ToInt32(fiLocalMap.Length), mapFileName);

                            bool found = false;
                            foreach (KeyValuePair <string, OverloadMap> map in newMapList)
                            {
                                if (newMap.SameZipFileName(map.Value))
                                {
                                    // We found a local map that matches the ZIP filename as found online.
                                    found = true;
                                    // Uppercase first char in map name and remove hidden marker if present.
                                    string mapZipName = fiLocalMap.Name;
                                    mapZipName        = mapZipName.Substring(0, 1).ToUpper() + mapZipName.Substring(1);
                                    mapZipName        = mapZipName.Replace(HiddenMarker, "");
                                    map.Value.ZipName = mapZipName;

                                    // Save full path to ZIP file in the DLC folder.
                                    map.Value.LocalDLCZipFileName = fiLocalMap.FullName;
                                }
                            }

                            if (!found)
                            {
                                newMapList.Add(mapFileName.ToLower(), newMap);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogErrorMessage(String.Format($"Unable to get local maps: {ex.Message}"));
                }
            }

            // Update maps.
            Maps = newMapList;
        }