Ejemplo n.º 1
0
// DIP Switches
void dip_handle() {
	// Handle the DIP switch file
	DipSwitches dipswitches(emulator);
	Xml xml;
	
	char dippath[512];
	snprintf(dippath, sizeof(dippath), "%s%s.dip", nstpaths.savedir, nstpaths.gamename);
	
	std::ifstream dipfile(dippath, std::ifstream::in|std::ifstream::binary);
	
	if (dipfile.is_open()) {
		xml.Read(dipfile);
		
		if (xml.GetRoot().IsType(L"dipswitches")) {
			Xml::Node root(xml.GetRoot());
			Xml::Node node(root.GetFirstChild());
			
			for (int i = 0; i < root.NumChildren(L"dip"); i++) {
				
				if (node.GetChild(L"value")) {
					dipswitches.SetValue(i, node.GetChild(L"value").GetUnsignedValue());
				}
				node = node.GetNextSibling();
			}
		}
		dipfile.close();
	}
	else {
		Xml::Node root(xml.GetRoot());
		
		root = xml.Create(L"dipswitches");
		root.AddAttribute(L"version", L"1.0");
		
		wchar_t wbuf[32];
		char buf[2];
		
		int numdips = dipswitches.NumDips();
	
		if (numdips > 0) {
			for (int i = 0; i < numdips; i++) {
				Xml::Node node(root.AddChild(L"dip"));
				
				mbstowcs(wbuf, dipswitches.GetDipName(i), sizeof(wbuf));
				node.AddChild(L"description", wbuf);
				
				snprintf(buf, sizeof(buf), "%d", dipswitches.GetValue(i));
				mbstowcs(wbuf, buf, sizeof(buf));
				node.AddChild(L"value", wbuf);
			}
		}
		
		std::ofstream dipout(dippath, std::ifstream::out|std::ifstream::binary);

		if (dipout.is_open()) {
			xml.Write(root, dipout);
		}
		
		dipout.close();
	}
}
Ejemplo n.º 2
0
void gtkui_cheats_save() {
	// Save the cheat list
	std::ofstream cheatfile(nstpaths.cheatpath, std::ifstream::out|std::ifstream::binary);
	
	if (cheatfile.is_open()) {
		
		GtkTreeModel *model;
		model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
		
		saveroot = (savexml.GetRoot());
		
		saveroot = savexml.Create( L"cheats" );
		saveroot.AddAttribute( L"version", L"1.0" );
		
		gtk_tree_model_foreach(GTK_TREE_MODEL(model), gtkui_cheats_write_list, NULL);
		
		savexml.Write(saveroot, cheatfile);
		cheatfile.close();
	}
	else { return; }
}
Ejemplo n.º 3
0
		void Netplay::SaveFile() const
		{
			if (games.state == Games::DIRTY)
			{
				//const Path path( Application::Instance::GetExePath(L"netplaylist.xml") );
				const Path path( Application::Instance::GetConfigPath(L"netplaylist.xml") );//bg

				if (!games.paths.empty())
				{
					try
					{
						typedef Nes::Core::Xml Xml;

						Xml xml;
						Xml::Node root( xml.Create( L"netplaylist" ) );
						root.AddAttribute( L"version", L"1.0" );

						for (Games::Paths::const_iterator it(games.paths.begin()), end(games.paths.end()); it != end; ++it)
							root.AddChild( L"file", it->Ptr() );

						Io::Stream::Out stream( path );
						xml.Write( root, stream );

						Io::Log() << "Netplay: saved game list to \"netplaylist.xml\"\r\n";
					}
					catch (...)
					{
						Io::Log() << "Netplay: warning, couldn't save game list to \"netplaylist.xml\"!\r\n";
					}
				}
				else if (path.FileExists())
				{
					if (Io::File::Delete( path.Ptr() ))
						Io::Log() << "Netplay: game list empty, deleted \"netplaylist.xml\"\r\n";
					else
						Io::Log() << "Netplay: warning, couldn't delete \"netplaylist.xml\"!\r\n";
				}
			}
		}
Ejemplo n.º 4
0
void on_cheatsave_clicked(GtkButton *button, gpointer user_data)
{
	GtkWidget *dialog;
	char defname[512];
	Cheats cheats(emulator);

	// nothing to export?
	if (cheats.NumCodes() == 0)
	{
		return;
	}

	defname[0] = '\0';
	strcpy(defname, rootname);
	strcat(defname, ".xml");

	dialog = gtk_file_chooser_dialog_new ("Export cheats (.xml)",
					      GTK_WINDOW(mainwindow),
					      GTK_FILE_CHOOSER_ACTION_SAVE,
					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
					      NULL);

	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), defname);

	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
	{
		char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

		std::ofstream stream( filename, std::ifstream::out|std::ifstream::binary );

		if (stream.is_open())
		{
			int i;
			Xml xml;
			Xml::Node root(xml.GetRoot());

			root = xml.Create( L"cheats" );
			root.AddAttribute( L"version", L"1.0" );

			for (i = 0; i < cheatlist.size(); i++)
			{
				Cheats::Code code;
				char buffer[9];
				wchar_t wbuffer[64];

				code = cheatlist[i].code;

				Xml::Node node( root.AddChild( L"cheat" ) );
				node.AddAttribute( L"enabled", cheatlist[i].enabled ? L"1" : L"0" );

				if (cheatlist[i].crc)
				{
					sprintf(buffer, "%08X", cheatlist[i].crc);
					mbstowcs(wbuffer, buffer, 63);
					node.AddAttribute( L"game", wbuffer );
				}

				if (NES_SUCCEEDED(cheats.GameGenieEncode(code, buffer)))
				{
					mbstowcs(wbuffer, buffer, 63);
					node.AddChild( L"genie", wbuffer );
				}

				if (NES_SUCCEEDED(cheats.ProActionRockyEncode(code, buffer)))
				{
					mbstowcs(wbuffer, buffer, 63);
					node.AddChild( L"rocky", wbuffer );
				}

				sprintf(buffer, "0x%04X", code.address);
				mbstowcs(wbuffer, buffer, 63);
				node.AddChild( L"address", wbuffer );
				sprintf(buffer, "0x%02X", code.value);
				mbstowcs(wbuffer, buffer, 63);
				node.AddChild( L"value", wbuffer );

				if (code.useCompare)
				{
					sprintf(buffer, "0x%02X", code.compare);
					mbstowcs(wbuffer, buffer, 63);
					node.AddChild( L"compare", wbuffer );
				}

				if (strlen(cheatlist[i].description))
				{
					mbstowcs(wbuffer, cheatlist[i].description, 63);
					node.AddChild( L"description", wbuffer );
				}
			}

			xml.Write( root, stream );
		}

		g_free (filename);
	}

	gtk_widget_destroy(dialog);
}