From 44aca76921c7cece1b5ac1be12c0d4f75fda4988 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Fri, 30 May 2008 12:42:38 +0000 Subject: [PATCH] make cycles reset to correct default value. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3166 --- include/setup.h | 7 +++++-- src/misc/setup.cpp | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/setup.h b/include/setup.h index a94c2592..a6ce9546 100644 --- a/include/setup.h +++ b/include/setup.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: setup.h,v 1.35 2008-04-29 08:23:16 qbix79 Exp $ */ +/* $Id: setup.h,v 1.36 2008-05-30 12:42:37 qbix79 Exp $ */ #ifndef DOSBOX_SETUP_H #define DOSBOX_SETUP_H @@ -130,6 +130,7 @@ public: char const* Get_help(); virtual void SetValue(std::string const& str)=0; Value const& GetValue() const { return value;} + Value const& Get_Default_Value() const { return default_value; } //CheckValue returns true if value is in suggested_values; //Type specific properties are encouraged to override this and check for type //specific features. @@ -138,6 +139,7 @@ public: void SetVal(Value const& in, bool forced,bool warn=true) {if(forced || CheckValue(in,warn)) value = in; else value = default_value;} virtual ~Property(){ } virtual const std::vector& GetValues() const; + Value::Etype Get_type(){return default_value.type;} protected: Value value; @@ -277,9 +279,10 @@ class Prop_multival:public Property{ protected: Section_prop* section; std::string seperator; + void make_default_value(); public: Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) { - value = ""; + default_value = value = ""; } Section_prop *GetSection() { return section; } const Section_prop *GetSection() const { return section; } diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index d71bfcb0..4e34fc52 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: setup.cpp,v 1.48 2008-04-29 08:23:16 qbix79 Exp $ */ +/* $Id: setup.cpp,v 1.49 2008-05-30 12:42:38 qbix79 Exp $ */ #include "dosbox.h" #include "cross.h" @@ -273,6 +273,23 @@ void Prop_hex::SetValue(std::string const& input){ SetVal(val,false,true); } +void Prop_multival::make_default_value(){ + Bitu i = 1; + Property *p = section->Get_prop(0); + if(!p) return; + + std::string result = p->Get_Default_Value().ToString(); + while( (p = section->Get_prop(i++)) ) { + std::string props = p->Get_Default_Value().ToString(); + if(props == "") continue; + result += seperator; result += props; + } + Value val(result,Value::V_STRING); + SetVal(val,false,true); +} + + + //TODO checkvalue stuff void Prop_multival_remain::SetValue(std::string const& input) { Value val(input,Value::V_STRING); @@ -303,6 +320,12 @@ void Prop_multival_remain::SetValue(std::string const& input) { in = local; local = ""; } + //Test Value. If it fails set default + Value valtest (in,p->Get_type()); + if(!p->CheckValue(valtest,true)) { + make_default_value(); + return; + } p->SetValue(in); } } @@ -324,21 +347,28 @@ void Prop_multival::SetValue(std::string const& input) { if(loc != string::npos) local.erase(0,loc); loc = local.find_first_of(seperator); string in = "";//default value - if(loc != string::npos) { //seperator found + if(loc != string::npos) { //seperator found in = local.substr(0,loc); local.erase(0,loc+1); } else if(local.size()) { //last argument in = local; local = ""; } + //Test Value. If it fails set default + Value valtest (in,p->Get_type()); + if(!p->CheckValue(valtest,true)) { + make_default_value(); + return; + } p->SetValue(in); + } } const std::vector& Property::GetValues() const { return suggested_values; } - const std::vector& Prop_multival::GetValues() const +const std::vector& Prop_multival::GetValues() const { Property *p = section->Get_prop(0); //No properties in this section. do nothing