Exemple #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);
            }
        }
Exemple #2
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.RawData;
            string previewPath = data.SaveGamePath;
            bool   preview     = data.Preview;

            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), worldName =
                        data.WorldName;
                    if (!string.IsNullOrWhiteSpace(worldName))
                    {
                        saveFolder = Path.Combine(saveFolder, data.WorldID.ToString("D5"));
                        saveFolder = Path.Combine(saveFolder, worldName);
                        saveName   = worldName;
                    }
                    if (!Directory.Exists(saveFolder))
                    {
                        Directory.CreateDirectory(saveFolder);
                    }
                    // Suffix file name with the current cycle
                    saveName += "_cycle_" + GameClock.Instance.GetCycle().ToString("0000.##") +
                                ".png";
                    // debugScreenShot is always false
                    path = Path.Combine(saveFolder, saveName);
                }
                PUtil.LogDebug("Saving screenshot to " + path);
                File.WriteAllBytes(path, data.RawData);
#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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Starts saving the colony preview image in the background.
        /// </summary>
        /// <param name="previewPath">The path to save the preview; ignored if saving a colony summary / timelapse image.</param>
        /// <param name="rawData">The image data to save, encoded as PNG.</param>
        /// <param name="worldID">The ID of the world to write.</param>
        /// <param name="preview">true if the image is a colony preview, or false otherwise.</param>
        public void Start(string previewPath, byte[] rawData, int worldID, bool preview)
        {
#if DEBUG
            PUtil.LogDebug("Encoding preview image");
#endif
            var data = new BackgroundTimelapseData(previewPath, rawData, worldID, preview);
            var task = new Thread(() => DoSave(data));
            Util.ApplyInvariantCultureToThread(task);
            task.Priority = ThreadPriority.BelowNormal;
            task.Name     = "Background Timelapser";
            Thread.MemoryBarrier();
            task.Start();
        }