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
use std::path::Path;
use crate::{parser::raws::info_txt::DFInfoFile, util};
use super::{raws, DFParser};
impl DFParser {
/// Parse a directory of raws, and return a JSON string of the parsed raws.
///
/// The first thing we do is check that the directory exists, and that it's a directory. If it doesn't
/// exist, or it's not a directory, we return an empty string
///
/// Arguments:
///
/// * `root_path`: The path to the directory containing the raws.
/// * `sourced_dir`: The directory the `root_path` was found under.
///
/// Returns:
///
/// A JSON string containing the raws for the given directory.
pub fn parse_raw_module_to_json_string<P: AsRef<Path>>(root_path: &P) -> String {
// Parse raws in the location
let serializable_vec = DFParser::parse_raw_module_into_serializable(root_path);
// Convert those raws into JSON strings
let json_vec = util::stringify_raw_vec(serializable_vec);
//3. Return the object array for this dfraw dir
format!("[{}]", json_vec.join(","))
}
/// It takes a path to a raw file, parses it, and returns a string representation of the parsed raws
///
/// Arguments:
///
/// * `raw_file`: The path to the raw file to read.
///
/// Returns:
///
/// A string.
pub fn parse_single_raw_file_to_json_string<P: AsRef<Path>>(raw_file: &P) -> String {
let parent_dir = util::get_parent_dir_name(raw_file);
let location = raws::RawModuleLocation::Unknown;
let info_text_file = DFInfoFile::new("manual-origin", location, &parent_dir);
let serializable_vec =
DFParser::parse_raws_from_single_file_into_serializable(raw_file, &info_text_file);
format!("[{}]", util::stringify_raw_vec(serializable_vec).join(","))
}
}