Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AvarianKnight committed Oct 28, 2021
1 parent 0a3b4c6 commit 3ed2fdd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.idea
.idea
exporter/data.json
9 changes: 9 additions & 0 deletions exporter/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Invoke-Expression -Command "cargo build --release"

if (Test-Path -Path ".\exporter.exe") {
Remove-Item -Path ".\exporter.exe"
}

if (Test-Path -Path ".\target\release\exporter.exe") {
Move-Item -Path ".\target\release\exporter.exe" -Destination ".\"
}
1 change: 0 additions & 1 deletion exporter/data.json

This file was deleted.

Binary file modified exporter/exporter.exe
Binary file not shown.
36 changes: 13 additions & 23 deletions exporter/src/carcols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,28 @@ use crate::{Model, MODEL_DATA};
pub(crate) fn handle_carcols(dir: &DirEntry) {
let file = File::open(dir.path()).unwrap();
let file = BufReader::new(file);

let parser = EventReader::new(file);

let mut data: String = String::new();
let mut model_name = String::new();
let mut game_name = String::new();
let mut data = String::new();
let mut model = Model::new();
for e in parser {
match e {
Ok(XmlEvent::StartElement { name, .. }) => {
data = name.to_string();
}
Ok(XmlEvent::StartElement { name, .. }) => { data = name.to_string() }

Ok(XmlEvent::Characters(chars)) => {
if data == "wheelName" {
data = String::new();
model_name = chars;
} else if data == "modShopLabel" {
game_name = chars;
match data.as_str() {
"wheelName" => { model.model_name = Some(chars) }
"modShopLabel" => { model.game_name = Some(chars) }
_ => {}
}
data.clear();
}
Err(e) => {
println!("Error: {} {}", dir.path().display(), e);
}
Err(e) => { println!("Error: {} {}", dir.path().display(), e) }
_ => {}
}
let str_new = String::new();
if model_name != str_new && game_name != str_new {
MODEL_DATA.lock().unwrap().push(Model{
model_name: model_name.clone(),
game_name: game_name.clone()
});
model_name.clear();
game_name.clear();
if model.model_name.is_some() && model.game_name.is_some() {
MODEL_DATA.lock().unwrap().push(model.clone());
model.clear();
}
}
}
29 changes: 24 additions & 5 deletions exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,41 @@ use std::io::{stdin, stdout, Read, Write};
use std::{fs, io};
use std::path::Path;
use std::fs::{DirEntry, File};
use serde_derive::{Serialize};
use serde_derive::Serialize;
use std::time::Instant;
use std::sync::{Mutex};

#[macro_use]
extern crate lazy_static;

lazy_static! {
pub static ref MODEL_DATA: Mutex<Vec<Model>> = Mutex::new(Vec::new());
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Model {
model_name: String,
game_name: String
model_name: Option<String>,
game_name: Option<String>
}

lazy_static! {
pub static ref MODEL_DATA: Mutex<Vec<Model>> = Mutex::new(Vec::new());
impl Model {
pub fn new() -> Self {
Self {
model_name: None,
game_name: None
}
}
fn clone(&self) -> Model {
Model {
model_name: self.model_name.clone(),
game_name: self.game_name.clone()
}
}
fn clear(&mut self) {
self.model_name = None;
self.game_name = None;
}
}

fn pause() {
Expand Down
62 changes: 15 additions & 47 deletions exporter/src/vehicles.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,33 @@
use std::fs::{DirEntry, File};
use std::io::{BufReader};
use serde_derive::Deserialize;
use xml::EventReader;
use xml::reader::XmlEvent;
use crate::{Model, MODEL_DATA};

#[derive(Deserialize, Debug)]
#[allow(non_snake_case, non_camel_case_types)]
struct CVehicleModelInfo__InitDataList {
InitDatas: InitDatas
}

#[derive(Deserialize, Debug)]
#[allow(non_snake_case, non_camel_case_types)]
struct InitDatas {
Item: Vec<Item>
}

#[derive(Deserialize, Debug)]
#[allow(non_snake_case, non_camel_case_types)]
struct Item {
modelName: String,
gameName: String
}

pub(crate) fn handle_vehicles(dir: &DirEntry) {
let file = File::open(dir.path()).unwrap();
let file_buf = BufReader::new(file);
let file = BufReader::new(file);
let parser = EventReader::new(file);

let parser = EventReader::new(file_buf);

let mut data: String = String::new();
let mut model_name = String::new();
let mut game_name = String::new();
let mut data = String::new();
let mut model = Model::new();
for e in parser {
match e {
Ok(XmlEvent::StartElement { name, .. }) => {
data = name.to_string();
}
Ok(XmlEvent::StartElement { name, .. }) => { data = name.to_string() }
Ok(XmlEvent::Characters(chars)) => {
if data == "modelName" {
data = String::new();
model_name = chars;
} else if data == "gameName" {
game_name = chars;
match data.as_str() {
"modelName" => { model.model_name = Some(chars) }
"gameName" => { model.game_name = Some(chars) }
_ => {}
}
data.clear();
}
Err(e) => {
println!("Error: {} {}", dir.path().display(), e);
}
Err(e) => { println!("Error: {} {}", dir.path().display(), e) }
_ => {}
}
let str_new = String::new();
if model_name != str_new && game_name != str_new {
MODEL_DATA.lock().unwrap().push(Model{
model_name: model_name.clone(),
game_name: game_name.clone()
});
model_name.clear();
game_name.clear();
if model.model_name.is_some() && model.game_name.is_some() {
MODEL_DATA.lock().unwrap().push(model.clone());
model.clear();
}
}

}
}

0 comments on commit 3ed2fdd

Please sign in to comment.