summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/ui/inifile.h
blob: 5a90b0d3d837b8f7b1b67928e848da7e80c5b209 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// license:BSD-3-Clause
// copyright-holders:Dankan1890
/***************************************************************************

    ui/inifile.h

    UI INIs file manager.

***************************************************************************/

#pragma once

#ifndef __UI_INIFILE_H__
#define __UI_INIFILE_H__

#include "ui/utils.h"

//-------------------------------------------------
//  INIFILE MANAGER
//-------------------------------------------------

class inifile_manager
{
public:
	// category structure
	struct IniCategoryIndex
	{
		IniCategoryIndex(std::string _name, long _offset) { name = _name; offset = _offset; }
		std::string name;
		long offset;
	};

	using categoryindex = std::vector<IniCategoryIndex>;

	// ini file structure
	struct IniFileIndex
	{
		IniFileIndex(std::string _name, categoryindex _category) { name = _name; category = _category; }
		std::string name;
		categoryindex category;
	};

	// construction/destruction
	inifile_manager(running_machine &machine);

	// getters
	running_machine &machine() const { return m_machine; }

	// load games from category
	void load_ini_category(std::vector<int> &temp_filter);

	// files indices
	std::vector<IniFileIndex> ini_index;
	static UINT16 current_file, current_category;

	std::string actual_file() { return ini_index[current_file].name; }
	std::string actual_category() { return ini_index[current_file].category[current_category].name; }

private:
	// init category index
	void init_category(std::string &filename);

	// init file index
	void directory_scan();

	// file open/close/seek
	bool parseopen(const char *filename);
	void parseclose() { if (fp != nullptr) fclose(fp); }

	// internal state
	running_machine &m_machine;  // reference to our machine
	std::string     m_fullpath;
	FILE			*fp = nullptr;
};

//-------------------------------------------------
//  FAVORITE MANAGER
//-------------------------------------------------

class favorite_manager
{
public:
	// construction/destruction
	favorite_manager(running_machine &machine);

	// favorite indices
	std::vector<ui_software_info> m_list;

	// getters
	running_machine &machine() const { return m_machine; }

	// add
	void add_favorite_game();
	void add_favorite_game(const game_driver *driver);
	void add_favorite_game(ui_software_info &swinfo);

	// check
	bool isgame_favorite();
	bool isgame_favorite(const game_driver *driver);
	bool isgame_favorite(ui_software_info &swinfo);

	// save
	void save_favorite_games();

	// remove
	void remove_favorite_game();
	void remove_favorite_game(ui_software_info &swinfo);

private:
	const char *favorite_filename = "favorites.ini";
	
	// current
	int m_current;

	// parse file ui_favorite
	void parse_favorite();

	// internal state
	running_machine &m_machine;  // reference to our machine
};

#endif  /* __UI_INIFILE_H__ */