コード例 #1
0
        public static bool TryOpenFile(string path, out LCSSave saveFile)
        {
            try
            {
                if (SaveData.GetFileFormat <LCSSave>(path, out FileFormat fmt))
                {
                    saveFile = SaveData.Load <LCSSave>(path, fmt);
                    return(saveFile != null);
                }

                saveFile = null;
                return(false);
            }
            catch (Exception e)
            {
                if (e is IOException ||
                    e is SecurityException ||
                    e is UnauthorizedAccessException ||
                    e is SerializationException ||
                    e is InvalidDataException)
                {
                    Log.Error(e);
                    saveFile = null;
                    return(false);
                }
                throw;
            }
        }
コード例 #2
0
        public void CloseFile()
        {
            if (!IsFileOpen)
            {
                return;
            }

            OnFileClosing();
            m_activeFile = null;
            OnFileClosed();
            OnPropertyChanged(nameof(ActiveFile));
        }
コード例 #3
0
        public void OpenFile(string path)
        {
            if (IsFileOpen)
            {
                throw FileAlreadyOpened();
            }

            OnFileOpening(path);
            // TODO: option to override file format autodetection
            m_activeFile = SaveData.Load <LCSSave>(path) ?? throw BadSaveData();
            TheSettings.AddRecentFile(path);
            LastWriteTime = File.GetLastWriteTime(path);
            ScriptVersion = GetScriptVersion();
            OnFileOpened();
        }