diff --git a/Cargo.lock b/Cargo.lock index 2c7e7821c..5bd490637 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,11 @@ dependencies = [ "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arrayvec" version = "0.5.1" @@ -89,6 +94,11 @@ name = "autocfg" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "base64" version = "0.12.2" @@ -123,6 +133,16 @@ name = "bitstream-io" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "blake2b_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block" version = "0.1.6" @@ -287,6 +307,11 @@ dependencies = [ "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "copyless" version = "0.1.4" @@ -513,6 +538,25 @@ name = "difference" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "dirs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs-sys 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dirs-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1827,6 +1871,16 @@ name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "redox_users" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "1.3.7" @@ -1896,6 +1950,7 @@ version = "0.1.0" dependencies = [ "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "cpal 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "embed-resource 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2027,6 +2082,17 @@ dependencies = [ "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rust-argon2" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2817,15 +2883,18 @@ dependencies = [ "checksum android_log-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8052e2d8aabbb8d556d6abbcce2a22b9590996c5f849b9c7ce4544a2e3b984e" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" +"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum ash 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69daec0742947f33a85931fa3cb0ce5f07929159dcbd1f0cbb5b2912e2978509" "checksum atom 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3c86699c3f02778ec07158376991c8f783dd1f2f95c579ffaf0738dc984b2fe2" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum base64 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e223af0dc48c96d4f8342ec01a4974f139df863896b316681efd36742f22cc67" "checksum bindgen 0.53.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6bb26d6a69a335b8cb0e7c7e9775cd5666611dc50a37177c3f2cedcfc040e8c8" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bitstream-io 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "614aa3f2bac03707e62a84d18a48dd3d9ea6171313fd5e6a53b5054d8ae74601" +"checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" "checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" "checksum bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" "checksum bumpalo 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12ae9db68ad7fac5fe51304d20f016c911539251075a214f8e663babefa35187" @@ -2845,6 +2914,7 @@ dependencies = [ "checksum console 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dea0f3e2e8d7dba335e913b97f9e1992c86c4399d54f8be1d31c8727d0652064" "checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" "checksum console_log 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494" +"checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" "checksum copyless 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ff9c56c9fb2a49c05ef0e431485a22400af20d33226dc0764d891d09e724127" "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" "checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" @@ -2869,6 +2939,8 @@ dependencies = [ "checksum deflate 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e5d2a2273fed52a7f947ee55b092c4057025d7a3e04e5ecdbd25d6c3fb1bd7" "checksum derivative 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" +"checksum dirs-sys 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" "checksum dispatch 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" "checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a" "checksum downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6" @@ -3017,10 +3089,12 @@ dependencies = [ "checksum rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" "checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" "checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" "checksum regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" "checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" "checksum rle-decode-fast 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" +"checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" "checksum rustc-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" "checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" "checksum rusttype 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0" diff --git a/core/src/avm1.rs b/core/src/avm1.rs index cb230d40f..948e55316 100644 --- a/core/src/avm1.rs +++ b/core/src/avm1.rs @@ -35,6 +35,7 @@ mod property; mod return_value; mod scope; pub mod script_object; +pub mod shared_object; mod sound_object; mod stage_object; mod super_object; @@ -43,7 +44,6 @@ mod value_object; pub mod xml_attributes_object; pub mod xml_idmap_object; pub mod xml_object; -pub mod shared_object; #[cfg(test)] mod tests; diff --git a/core/src/avm1/globals/shared_object.rs b/core/src/avm1/globals/shared_object.rs index c01134bc3..f13da708a 100644 --- a/core/src/avm1/globals/shared_object.rs +++ b/core/src/avm1/globals/shared_object.rs @@ -1,16 +1,13 @@ use crate::avm1::function::{Executable, FunctionObject}; use crate::avm1::return_value::ReturnValue; -use crate::avm1::{Avm1, Error, Object, ObjectPtr, ScriptObject, TObject, Value}; +use crate::avm1::{Avm1, Error, Object, TObject, Value}; use crate::context::UpdateContext; use enumset::EnumSet; -use gc_arena::{GcCell, MutationContext, Collect}; -use crate::avm1::property::Attribute; -use crate::display_object::DisplayObject; -use crate::avm1::sound_object::SoundObject; +use gc_arena::MutationContext; + use crate::avm1::shared_object::SharedObject; use json::JsonValue; -use std::fmt; pub fn delete_all<'gc>( _avm: &mut Avm1<'gc>, @@ -45,7 +42,7 @@ fn recursive_serialize<'gc>( let elem = obj.get(k, avm, action_context).unwrap(); match elem { - Value::Undefined => {}, + Value::Undefined => {} Value::Null => json_obj[k] = JsonValue::Null, Value::Bool(b) => json_obj[k] = b.into(), Value::Number(f) => json_obj[k] = f.into(), @@ -137,7 +134,8 @@ pub fn get_local<'gc>( _this: Object<'gc>, args: &[Value<'gc>], ) -> Result, Error> { - let name = args.get(0) + let name = args + .get(0) .unwrap_or(&Value::Undefined) .to_owned() .coerce_to_string(avm, action_context)?; @@ -411,8 +409,8 @@ pub fn create_proto<'gc>( proto: Object<'gc>, fn_proto: Object<'gc>, ) -> Object<'gc> { - let shared_obj = SharedObject::empty_shared_obj(gc_context, Some(proto)); - let mut object = shared_obj.as_script_object().unwrap(); + let shared_obj = SharedObject::empty_shared_obj(gc_context, Some(proto)); + let mut object = shared_obj.as_script_object().unwrap(); object.force_set_function("clear", clear, gc_context, EnumSet::empty(), Some(fn_proto)); diff --git a/core/src/avm1/object.rs b/core/src/avm1/object.rs index 9b439070b..989d531d0 100644 --- a/core/src/avm1/object.rs +++ b/core/src/avm1/object.rs @@ -4,9 +4,9 @@ use crate::avm1::error::Error; use crate::avm1::function::{Executable, FunctionObject}; use crate::avm1::property::Attribute; use crate::avm1::return_value::ReturnValue; +use crate::avm1::shared_object::SharedObject; use crate::avm1::super_object::SuperObject; use crate::avm1::value_object::ValueObject; -use crate::avm1::shared_object::SharedObject; use crate::avm1::xml_attributes_object::XMLAttributesObject; use crate::avm1::xml_idmap_object::XMLIDMapObject; @@ -15,7 +15,7 @@ use crate::avm1::{Avm1, ScriptObject, SoundObject, StageObject, UpdateContext, V use crate::display_object::DisplayObject; use crate::xml::XMLNode; use enumset::EnumSet; -use gc_arena::{Collect, GcCell, MutationContext}; +use gc_arena::{Collect, MutationContext}; use ruffle_macros::enum_trait_object; use std::borrow::Cow; use std::fmt::Debug; diff --git a/core/src/avm1/shared_object.rs b/core/src/avm1/shared_object.rs index 988b39497..2f8a29823 100644 --- a/core/src/avm1/shared_object.rs +++ b/core/src/avm1/shared_object.rs @@ -1,14 +1,13 @@ -use crate::avm1::function::{Executable, FunctionObject}; +use crate::avm1::function::Executable; +use crate::avm1::property::Attribute; use crate::avm1::return_value::ReturnValue; +use crate::avm1::sound_object::SoundObject; use crate::avm1::{Avm1, Error, Object, ObjectPtr, ScriptObject, TObject, Value}; use crate::context::UpdateContext; -use enumset::EnumSet; -use gc_arena::{GcCell, MutationContext, Collect}; -use crate::avm1::property::Attribute; use crate::display_object::DisplayObject; -use crate::avm1::sound_object::SoundObject; +use enumset::EnumSet; +use gc_arena::{Collect, GcCell, MutationContext}; -use json::JsonValue; use std::fmt; /// A SharedObject @@ -57,7 +56,12 @@ impl<'gc> SharedObject<'gc> { } pub fn get_name(&self) -> String { - self.0.read().name.as_ref().cloned().unwrap_or("".to_owned()) + self.0 + .read() + .name + .as_ref() + .cloned() + .unwrap_or_else(|| "".to_string()) } fn base(self) -> ScriptObject<'gc> { @@ -116,7 +120,10 @@ impl<'gc> TObject<'gc> for SharedObject<'gc> { _this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error> { - Ok(SharedObject::empty_shared_obj(context.gc_context, Some(avm.prototypes.shared_object)).into()) + Ok( + SharedObject::empty_shared_obj(context.gc_context, Some(avm.prototypes.shared_object)) + .into(), + ) } fn delete( diff --git a/core/src/backend/storage.rs b/core/src/backend/storage.rs index 33d041b51..5329eea34 100644 --- a/core/src/backend/storage.rs +++ b/core/src/backend/storage.rs @@ -2,15 +2,15 @@ use downcast_rs::Downcast; use std::collections::HashMap; pub trait StorageBackend: Downcast { - fn get_string(&self, name: &String) -> Option; + fn get_string(&self, name: &str) -> Option; - fn put_string(&mut self, name: &String, value: String) -> bool; + fn put_string(&mut self, name: &str, value: String) -> bool; - fn get_size(&self, name: &String) -> Option { + fn get_size(&self, name: &str) -> Option { self.get_string(name).map(|x| x.as_bytes().len()) } - fn remove_key(&mut self, name: &String); + fn remove_key(&mut self, name: &str); } impl_downcast!(StorageBackend); @@ -27,16 +27,16 @@ impl Default for MemoryStorageBackend { } impl StorageBackend for MemoryStorageBackend { - fn get_string(&self, name: &String) -> Option { + fn get_string(&self, name: &str) -> Option { self.map.get(name).cloned() } - fn put_string(&mut self, name: &String, value: String) -> bool { - self.map.insert(name.clone(), value); + fn put_string(&mut self, name: &str, value: String) -> bool { + self.map.insert(name.into(), value); true } - fn remove_key(&mut self, name: &String) { + fn remove_key(&mut self, name: &str) { self.map.remove(name); } } diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index 720fe78dd..2bf4a9f2f 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -22,6 +22,7 @@ winit = "0.22" webbrowser = "0.5.4" url = "2.1.1" clipboard = "0.5.0" +dirs = "2.0" [target.'cfg(windows)'.build-dependencies] embed-resource = "1" diff --git a/desktop/src/storage.rs b/desktop/src/storage.rs index 5745bfaae..d935c8dfd 100644 --- a/desktop/src/storage.rs +++ b/desktop/src/storage.rs @@ -2,34 +2,31 @@ use ruffle_core::backend::storage::StorageBackend; use std::fs; use std::fs::File; use std::io::{Read, Write}; -use std::path::Path; -use std::string::ToString; +use std::path::{Path, PathBuf}; pub struct DiskStorageBackend { - base_path: String, + base_path: PathBuf, } impl DiskStorageBackend { pub fn new() -> Self { - let bp = "/home/cub3d/.local/share/ruffle/".to_string(); + let base_path = dirs::data_local_dir().unwrap().join(Path::new("ruffle")); // Create a base dir if one doesn't exist yet - let base_path = Path::new(&bp); - if !base_path.exists() { + if !&base_path.exists() { log::info!("Creating storage dir"); - if let Err(r) = fs::create_dir_all(base_path) { + if let Err(r) = fs::create_dir_all(&base_path) { log::warn!("Unable to create storage dir {}", r); } } - DiskStorageBackend { base_path: bp } + DiskStorageBackend { base_path } } } impl StorageBackend for DiskStorageBackend { - fn get_string(&self, name: &String) -> Option { - let base_path = Path::new(&self.base_path); - let full_path = base_path.join(Path::new(name)); + fn get_string(&self, name: &str) -> Option { + let full_path = self.base_path.join(Path::new(name)); match File::open(full_path) { Ok(mut file) => { @@ -49,11 +46,10 @@ impl StorageBackend for DiskStorageBackend { } - fn put_string(&mut self, name: &String, value: String) -> bool { - let base_path = Path::new(&self.base_path); - let full_path = base_path.join(Path::new(name)); + fn put_string(&mut self, name: &str, value: String) -> bool { + let full_path = self.base_path.join(Path::new(name)); - match File::create(full_path.clone()) { + match File::create(full_path) { Ok(mut file) => { if let Err(r) = file.write_all(value.as_bytes()) { log::warn!("Unable to write file content {:?}", r); @@ -69,9 +65,8 @@ impl StorageBackend for DiskStorageBackend { } } - fn remove_key(&mut self, name: &String) { - let base_path = Path::new(&self.base_path); - let full_path = base_path.join(Path::new(name)); + fn remove_key(&mut self, name: &str) { + let full_path = self.base_path.join(Path::new(name)); log::info!("[storage] Saved {} to {:?}", value, full_path); }