コード例 #1
0
ファイル: sound_animation.cpp プロジェクト: CCChaos/RyzomCore
void CSoundAnimation::save()
{
	// File stream
	COFile file;
	vector<NLMISC::CSheetId>	sounds;

	// Open the file
	if (!file.open(_Filename.c_str()))
	{
		throw NLMISC::Exception("Can't open the file for writing");
	}

	// Create the XML stream
	COXml output;

	// Init
	if (output.init (&file, "1.0"))
	{
		xmlDocPtr xmlDoc = output.getDocument();

		// Create the first node
		xmlNodePtr root = xmlNewDocNode (xmlDoc, NULL, (const xmlChar*)"SOUNDANIMATION", NULL);
		xmlDocSetRootElement (xmlDoc, root);

		vector<CSoundAnimMarker*>::iterator iter;
		for (iter = _Markers.begin(); iter != _Markers.end(); iter++)
		{
			CSoundAnimMarker* marker = (*iter);

			set<string>::iterator iter;

			char s[64];
			smprintf(s, 64, "%f", marker->getTime());

			xmlNodePtr markerNode = xmlNewChild (root, NULL, (const xmlChar*)"MARKER", NULL);
			xmlSetProp (markerNode, (const xmlChar*) "time", (const xmlChar*) s);

			marker->getSounds(sounds);

			vector<NLMISC::CSheetId>::iterator iter2;
			for (iter2 = sounds.begin(); iter2 != sounds.end(); iter2++)
			{
				xmlNodePtr soundNode = xmlNewChild ( markerNode, NULL, (const xmlChar*)"SOUND", NULL );
				xmlSetProp (soundNode, (const xmlChar*)"name", (const xmlChar*)iter2->toString().c_str() /*CStringMapper::unmap(*iter2).c_str()*/);
			}

			sounds.clear();
		}

		// Flush the stream, write all the output file
		output.flush ();
	}

	// Close the file
	file.close ();

	_Dirty = false;
}
コード例 #2
0
// ---------------------------------------------------------------------------
void CGeorgesImpl::MakeTyp( const std::string& filename, TType type, TUI ui, const std::string& _min, const std::string& _max, const std::string& _default, const std::vector< std::pair< std::string, std::string > >* const _pvpredef )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// Create a type
	CType t;
	t.Type = (CType::TType)type;
	t.UIType = (CType::TUI)ui;
	t.Min= _min;
	t.Max = _max;
	t.Default = _default;

	if (_pvpredef)
	{
		t.Definitions.resize (_pvpredef->size ());
		uint i;
		for (i=0; i<_pvpredef->size (); i++)
		{
			t.Definitions[i].Label = (*_pvpredef)[i].first;
			t.Definitions[i].Value = (*_pvpredef)[i].second;
		}
	}

	// Save the type
	COFile output;
	if (output.open (filename))
	{
		try
		{
			// XML stream
			COXml outputXml;
			outputXml.init (&output);

			// Write
			t.write (outputXml.getDocument ());
		}
		catch (Exception &e)
		{
			nlwarning ("Error during writing file '%s' : ", filename.c_str (), e.what ());
		}
	}
	else
	{
		nlwarning ("Can't open the file %s for writing", filename.c_str ());
	}
}
コード例 #3
0
// ---------------------------------------------------------------------------
void CGeorgesImpl::createInstanceFile (const std::string &_sxFullnameWithoutExt, const std::string &_dfnname)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	CFormLoader formLoader;
	CFormDfn *dfn = formLoader.loadFormDfn (_dfnname.c_str(), false);
	if (!dfn)
	{
		char msg[512];
		smprintf (msg, 512, "Can't load DFN '%s'", _dfnname);
		theApp.outputError (msg);
		return;
	}

	NLMISC::CSmartPtr<NLGEORGES::UForm> Form = new CForm;

	std::string fullName;
	fullName = _sxFullnameWithoutExt + ".";

	int i = 0;
	if (_dfnname[i] == '.') ++i;
	for (; i < (int)_dfnname.size(); ++i)
	{
		if (_dfnname[i] == '.') break;
		fullName += _dfnname[i];
	}

	((CFormElmStruct*)&Form->getRootNode ())->build (dfn);
	COFile f;
	COXml ox;
	if (f.open (fullName))
	{
		ox.init(&f);
		((NLGEORGES::CForm*)((UForm*)Form))->write (ox.getDocument(), _sxFullnameWithoutExt.c_str ());
		ox.flush();
		f.close();
	}
	else
	{
		char msg[512];
		smprintf (msg, 512, "Can't write '%s'", fullName);
		theApp.outputError (msg);
		return;
	}
}
コード例 #4
0
BOOL CGeorgesEditDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	// Get focus
	CWnd *focus = CWnd::GetFocus ();
	::SetFocus (NULL);

	// Open the filt
	COFile file;
	if (file.open (lpszPathName))
	{
		try
		{
			// Xml stream
			COXml xmlStream;
			xmlStream.init (&file);

			if (isType())
			{
				nlassert (Type != NULL);
			
				// Write the file
				// Modified ?
				if (IsModified ())
				{
					Type->Header.MinorVersion++;
					flushValueChange ();
				}
				Type->write (xmlStream.getDocument (), theApp.Georges4CVS);
				modify (NULL, NULL, false);
				flushValueChange ();
				UpdateAllViews (NULL);
				return TRUE;
			}
			else if (isDfn ())
			{
				nlassert (Dfn != NULL);

				// Write the file
				if (IsModified ())
				{
					Dfn->Header.MinorVersion++;
					flushValueChange ();
				}
				Dfn->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
				modify (NULL, NULL, false);
				UpdateAllViews (NULL);
				return TRUE;
			}
			else
			{
				nlassert (Form != NULL);

				// Write the file
				if (IsModified ())
				{
					((CForm*)(UForm*)Form)->Header.MinorVersion++;				
					flushValueChange ();
				}
				((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
				if (strcmp (xmlStream.getErrorString (), "") != 0)
				{
					char message[512];
					smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ());
					theApp.outputError (message);
				}
				modify (NULL, NULL, false);
				flushValueChange ();
				UpdateAllViews (NULL);

				// Get the left view
				CView* pView = getLeftView ();

				return TRUE;
			}

		}
		catch (Exception &e)
		{
			char message[512];
			smprintf (message, 512, "Error while loading file: %s", e.what());
			theApp.outputError (message);
			return FALSE;
		}
	}
	else
	{
		char message[512];
		smprintf (message, 512, "Can't open the file %s for writing.", lpszPathName);
		theApp.outputError (message);
		return FALSE;
	}

	// Set focus
	focus->SetFocus ();

	return FALSE;
	//return CDocument::OnSaveDocument(lpszPathName);
}