Skip to content

Commit

Permalink
fixed data file bug again.... :(
Browse files Browse the repository at this point in the history
  • Loading branch information
DubskySteam committed Mar 24, 2023
1 parent 6216dca commit ca8347b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ___
3. Create a folder called "PoE-RPC" in "C:\Users\%username%\Documents\"
4. Copy "data.json" into it
5. Open "data.json" with any editor.
6. Replace the content of the path variable with a path to your client.txt
6. Replace the content of the "clienttxt" variable with a path to your client.txt
7. Run the program
8. On the very first start, enter your level and class name and hit "Override".

Expand Down
3 changes: 2 additions & 1 deletion src/js/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let player = {
path: "E:/SteamLibrary/steamapps/common/Path of Exile/logs/Client.txt",
data: "Unknown",
clienttxt: "Unknown",
level: 0,
type: "Unknown",
area: "Unknown",
Expand Down
40 changes: 22 additions & 18 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const DiscordRPC = require("discord-rpc");
var os = require('os');
const { app, BrowserWindow, Menu, ipcMain } = require("electron");
var PathOfExileLog = require("poe-log-monitor");
let { player } = require("./js/data");
const path = require("path");
const url = require("url");
const fs = require("fs");
let win;
let winUser = os.userInfo().username;
let poelog = new PathOfExileLog({logfile: player.path});
var os = require("os");
var osUser = os.userInfo().username;
player.data = "C:/Users/" + osUser + "/Documents/PoE-RPC/data.json";

const rpc = new DiscordRPC.Client({
transport: "ipc",
});


const createWindow = () => {
win = new BrowserWindow({
width: 720,
Expand All @@ -39,11 +38,11 @@ app.whenReady().then(() => {
largeImageKey: "poe_logo",
largeImageText: "EU Server",
});
readDataFile();
//readDataFile();
});

app.on("window-all-closed", () => {
fs.writeFile("C:/Users/" + winUser + "/Documents/PoE-RPC/data.json", JSON.stringify(player), (err) => {
fs.writeFile(player.data, JSON.stringify(player), (err) => {
if (err) {
win.webContents.send("error", "Error! Couldn't write to data file");
return;
Expand All @@ -54,7 +53,7 @@ app.on("window-all-closed", () => {
});

function readDataFile() {
fs.readFile("C:/Users/" + winUser + "/Documents/PoE-RPC/data.json", "utf8", (err, data) => {
fs.readFile(player.data, "utf8", (err, data) => {
if (err) {
win.webContents.send("error", "Error! Couldn't read data file");
return;
Expand All @@ -63,15 +62,28 @@ function readDataFile() {
player.type = json.type;
player.level = json.level;
player.area = json.area;
player.path = json.path;
player.clienttxt = json.clienttxt;
ready=true;
console.log("Read data file");
});

console.log(player.clienttxt)
let poelog = new PathOfExileLog({ logfile: player.clienttxt });

poelog.on("area", (area) => {
player.area = area.name;
console.log(area.name);
});

poelog.on("level", (level) => {
player.level = area.level;
});
});
}

ipcMain.on("override", (event, level, type) => {
player.level = level;
player.type = type;
fs.writeFile("C:/Users" + winUser + "/Documents/PoE-RPC/data.json", JSON.stringify(player), (err) => {
fs.writeFile(player.data, JSON.stringify(player), (err) => {
if (err) {
win.webContents.send("error", "Error! Couldn't write to data file");
return;
Expand All @@ -80,14 +92,6 @@ ipcMain.on("override", (event, level, type) => {
});
});

poelog.on("area", (area) => {
player.area = area.name;
});

poelog.on("level", (level) => {
player.level = area.level;
});

setInterval(() => {
win.webContents.send("data", player.type, player.level, player.area);
rpc.setActivity({
Expand Down

0 comments on commit ca8347b

Please sign in to comment.