Exemplo n.º 1
0
        // Wypakowuje z archiwum wskazany po identyfikatorze plik do wskazanego po ścieżce katalogu
        public void Extract(int id, string destPath)
        {
            if (!IsOpen)
            {
                throw new Exception("Archiwum nieotwarte");
            }

            if (!ArchiveKey.IsDerived)
            {
                throw new Exception("Klucz niewyprowadzony");
            }

            SQLiteCommand command = new SQLiteCommand(Connection);

            command.CommandText = "SELECT name_l, length(name), name, content_l, length(content), content, iv FROM FileData WHERE id='" + Convert.ToString(id) + "';";

            SQLiteDataReader reader = command.ExecuteReader();

            FileData file = null;

            while (reader.Read())
            {
                int nameLength = reader.GetInt32(0);

                int    nameBlobLength = reader.GetInt32(1);
                byte[] fileName       = new byte[nameBlobLength];
                reader.GetBytes(2, 0, fileName, 0, nameBlobLength);

                int contentLength = reader.GetInt32(3);

                int    contentBlobLength = reader.GetInt32(4);
                byte[] content           = new byte[contentBlobLength];
                reader.GetBytes(5, 0, content, 0, contentBlobLength);

                byte[] iv = new byte[EncryptionKey.BlockLength];
                reader.GetBytes(6, 0, iv, 0, EncryptionKey.BlockLength);

                file = FileData.Create(nameLength, fileName, contentLength, content, iv);
            }

            if (file != null)
            {
                FileEncryptor.DecryptFile(file, ArchiveKey);

                if (IsCompressed)
                {
                    FileCompressor.DecompressFile(file);
                }

                File.WriteAllBytes(Path.Combine(destPath, file.NameStr), file.Content);
            }
            else
            {
                throw new Exception(string.Format("Nie udało się odczytać danych pliku o id={0}", id));
            }
        }
        private static bool Decrypt()
        {
#if DEBUG
            {
                return(true);
            }
#else
            {
                return(FileEncryptor.DecryptFile(GetSettingsFileName, _key));
            }
#endif
        }
Exemplo n.º 3
0
        public void LoadGameFromDisk()
        {
            base.Scenario.EnableLoadAndSave = false;
            if (!File.Exists("GameData/Save/" + this.LoadFileName))
            {
                base.Scenario.EnableLoadAndSave = true;
            }
            else
            {
                this.Plugins.DateRunnerPlugin.Reset();
                this.Plugins.GameRecordPlugin.Clear();
                this.Plugins.GameRecordPlugin.RemoveDisableRects();
                this.Plugins.AirViewPlugin.RemoveDisableRects();

                string realPath = this.LoadFileName.Substring(0, this.LoadFileName.Length - 4) + ".mdb";

                if (this.LoadFileName.EndsWith(".zhs"))
                {
                    FileEncryptor.DecryptFile("GameData/Save/" + this.LoadFileName, "GameData/Save/" + realPath, GlobalVariables.cryptKey);
                }

                OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder
                {
                    DataSource = "GameData/Save/" + realPath,
                    Provider   = "Microsoft.Jet.OLEDB.4.0"
                };
                base.Scenario.LoadSaveFileFromDatabase(builder.ConnectionString, this.LoadFileName);

                if (GlobalVariables.EncryptSave)
                {
                    File.Delete("GameData/Save/" + realPath);
                }

                //this.mainMapLayer.jiazaibeijingtupian();

                this.chushihuajianzhubiaotiheqizi();
                this.gengxinyoucelan();

                base.Scenario.EnableLoadAndSave = true;
            }
        }
Exemplo n.º 4
0
        public void LoadGameFromDisk(String fileName)
        {
            base.Scenario.EnableLoadAndSave = false;
            if (!File.Exists(fileName))
            {
                base.Scenario.EnableLoadAndSave = true;
            }
            else
            {
                this.Plugins.DateRunnerPlugin.Reset();
                this.Plugins.GameRecordPlugin.Clear();
                this.Plugins.GameRecordPlugin.RemoveDisableRects();
                this.Plugins.AirViewPlugin.RemoveDisableRects();

                string realPath = fileName.Substring(0, fileName.Length - 4) + ".mdb";

                if (this.LoadFileName.EndsWith(".zhs"))
                {
                    FileEncryptor.DecryptFile(fileName, realPath, GlobalVariables.cryptKey);
                }

                OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder
                {
                    DataSource = realPath,
                    Provider   = "Microsoft.Jet.OLEDB.4.0"
                };
                base.Scenario.LoadSaveFileFromDatabase(builder.ConnectionString, fileName);

                if (GlobalVariables.EncryptSave)
                {
                    File.Delete(realPath);
                }

                this.ReloadScreenData();

                base.Scenario.EnableLoadAndSave = true;
            }
        }