Пример #1
0
        /// <summary>
        /// Saves a preview image to disk in the background.
        /// </summary>
        /// <param name="data">The uncompressed preview image data.</param>
        private void DoSave(BackgroundTimelapseData data)
        {
            var    screenData  = data.TextureData;
            string previewPath = data.SaveGamePath;
            bool   preview     = data.Preview;

            byte[] rawPNG;
            // Encode PNG (this is the woofy part on high resolution)
#if DEBUG
            PUtil.LogDebug("Encoding preview image");
#endif
            try {
                rawPNG = screenData.EncodeToPNG();
            } finally {
                data.Dispose();
            }
            try {
                string retiredPath = Path.Combine(Util.RootFolder(), Util.
                                                  GetRetiredColoniesFolderName());
                if (!Directory.Exists(retiredPath))
                {
                    // This call is recursive
                    Directory.CreateDirectory(retiredPath);
                }
                string saveName = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.
                                                                             BaseName), path;
                if (preview)
                {
                    // Colony preview
                    path = Path.ChangeExtension(previewPath, ".png");
                }
                else
                {
                    string saveFolder = Path.Combine(retiredPath, saveName);
                    if (!Directory.Exists(saveFolder))
                    {
                        Directory.CreateDirectory(saveFolder);
                    }
                    // Suffix file name with the current cycle
                    saveName += "_cycle" + GameClock.Instance.GetCycle().ToString("0000.##");
                    // debugScreenShot is always false
                    path = Path.Combine(saveFolder, saveName);
                }
                PUtil.LogDebug("Saving screenshot to " + path);
                File.WriteAllBytes(path, rawPNG);
                rawPNG = null;
#if DEBUG
                PUtil.LogDebug("Background screenshot save complete");
#endif
            } catch (IOException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            } catch (UnauthorizedAccessException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            }
        }