mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-08 04:04:53 +02:00
feature: delete all mods button
This commit is contained in:
parent
caba55241b
commit
5d9900d34a
@ -165,8 +165,6 @@ func (mods *Mods) downloadMod(url string, filename string, mod_id string) (error
|
|||||||
func (mods *Mods) uploadMod(header *multipart.FileHeader) (error) {
|
func (mods *Mods) uploadMod(header *multipart.FileHeader) (error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
log.Printf("filename of the uploaded file: %s", header.Filename)
|
|
||||||
|
|
||||||
if filepath.Ext(header.Filename) != ".zip" {
|
if filepath.Ext(header.Filename) != ".zip" {
|
||||||
log.Print("The uploaded file wasn't a zip-file -> ignore it")
|
log.Print("The uploaded file wasn't a zip-file -> ignore it")
|
||||||
return nil //simply do nothing xD
|
return nil //simply do nothing xD
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModSimple struct {
|
type ModSimple struct {
|
||||||
@ -36,8 +37,25 @@ func (mod_simple_list *ModSimpleList) listInstalledMods() (error) {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
file, err := ioutil.ReadFile(mod_simple_list.Destination + "/mod-list.json")
|
file, err := ioutil.ReadFile(mod_simple_list.Destination + "/mod-list.json")
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Println("no mod-list.json found ... create new one ...")
|
||||||
|
|
||||||
|
//mod-list.json does not exist, create one
|
||||||
|
base_mod := ModSimple{
|
||||||
|
Name: "base",
|
||||||
|
Enabled: true,
|
||||||
|
}
|
||||||
|
mod_simple_list.Mods = append(mod_simple_list.Mods, base_mod)
|
||||||
|
err = mod_simple_list.saveModInfoJson()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error saving mod-list.json: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ModSimpleList ... error read the mod-info.json: %s", err)
|
log.Printf("ModSimpleList ... error read or write the mod-info.json: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
src/mods.go
26
src/mods.go
@ -185,6 +185,32 @@ func getModDetails(modId string) (string, error, int) {
|
|||||||
return text_string, nil, resp.StatusCode
|
return text_string, nil, resp.StatusCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteAllMods() (error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
mods_dir_info, err := os.Stat(config.FactorioModsDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error getting stats of FactorioModsDir: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mods_dir_perm := mods_dir_info.Mode().Perm()
|
||||||
|
|
||||||
|
err = os.RemoveAll(config.FactorioModsDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("removing FactorioModsDir failed: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Mkdir(config.FactorioModsDir, mods_dir_perm)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error recreating modPackDir: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func modStartUp() {
|
func modStartUp() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -292,6 +292,34 @@ func DeleteModHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteAllModsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var err error
|
||||||
|
resp := JSONResponse{
|
||||||
|
Success: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||||
|
|
||||||
|
//delete mods folder
|
||||||
|
err = deleteAllMods()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
resp.Data = fmt.Sprintf("Error in deleteMod: %s", err)
|
||||||
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||||
|
log.Printf("Error in DeleteModHandler: %s", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Data = nil
|
||||||
|
resp.Success = true
|
||||||
|
|
||||||
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||||
|
log.Printf("Error in DeleteModHandler: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateModHandler(w http.ResponseWriter, r *http.Request) {
|
func UpdateModHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
resp := JSONResponse{
|
resp := JSONResponse{
|
||||||
|
@ -193,6 +193,11 @@ var apiRoutes = Routes{
|
|||||||
"POST",
|
"POST",
|
||||||
"/mods/delete",
|
"/mods/delete",
|
||||||
DeleteModHandler,
|
DeleteModHandler,
|
||||||
|
}, {
|
||||||
|
"DeleteAllMods",
|
||||||
|
"POST",
|
||||||
|
"/mods/delete/all",
|
||||||
|
DeleteAllModsHandler,
|
||||||
}, {
|
}, {
|
||||||
"UpdateMod",
|
"UpdateMod",
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -83,6 +83,16 @@ class ModOverview extends React.Component {
|
|||||||
<div className="box-header" data-widget="collapse" style={{cursor: "pointer"}}>
|
<div className="box-header" data-widget="collapse" style={{cursor: "pointer"}}>
|
||||||
<i className="fa fa-minus"></i>
|
<i className="fa fa-minus"></i>
|
||||||
<h3 className="box-title">Manage Mods</h3>
|
<h3 className="box-title">Manage Mods</h3>
|
||||||
|
<div className="box-tools pull-right">
|
||||||
|
{
|
||||||
|
this.props.installedMods != null ?
|
||||||
|
<NativeListener onClick={this.props.deleteAll}>
|
||||||
|
<button className="btn btn-box-tool btn-danger" style={{color: "#fff"}}>Delete ALL
|
||||||
|
</button>
|
||||||
|
</NativeListener>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ModManager
|
<ModManager
|
||||||
@ -110,6 +120,7 @@ ModOverview.propTypes = {
|
|||||||
submitFactorioLogin: React.PropTypes.func.isRequired,
|
submitFactorioLogin: React.PropTypes.func.isRequired,
|
||||||
toggleMod: React.PropTypes.func.isRequired,
|
toggleMod: React.PropTypes.func.isRequired,
|
||||||
deleteMod: React.PropTypes.func.isRequired,
|
deleteMod: React.PropTypes.func.isRequired,
|
||||||
|
deleteAll: React.PropTypes.func.isRequired,
|
||||||
updateMod: React.PropTypes.func.isRequired,
|
updateMod: React.PropTypes.func.isRequired,
|
||||||
uploadModSuccessHandler: React.PropTypes.func.isRequired,
|
uploadModSuccessHandler: React.PropTypes.func.isRequired,
|
||||||
logged_in: React.PropTypes.bool.isRequired,
|
logged_in: React.PropTypes.bool.isRequired,
|
||||||
|
@ -17,10 +17,11 @@ class ModsContent extends React.Component {
|
|||||||
this.updateModHandler = this.updateModHandler.bind(this);
|
this.updateModHandler = this.updateModHandler.bind(this);
|
||||||
this.uploadModSuccessHandler = this.uploadModSuccessHandler.bind(this);
|
this.uploadModSuccessHandler = this.uploadModSuccessHandler.bind(this);
|
||||||
this.factorioLogoutHandler = this.factorioLogoutHandler.bind(this);
|
this.factorioLogoutHandler = this.factorioLogoutHandler.bind(this);
|
||||||
|
this.deleteAllHandler = this.deleteAllHandler.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
logged_in: false,
|
logged_in: false,
|
||||||
installedMods: [],
|
installedMods: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,6 +318,47 @@ class ModsContent extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteAllHandler(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
let class_this = this;
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: "Delete Mod?",
|
||||||
|
text: "This will delete ALL mods and can't be redone!<br> Are you sure?",
|
||||||
|
type: "info",
|
||||||
|
showCancelButton: true,
|
||||||
|
closeOnConfirm: false,
|
||||||
|
confirmButtonText: "Yes, Delete ALL!",
|
||||||
|
cancelButtonText: "Cancel",
|
||||||
|
showLoaderOnConfirm: true,
|
||||||
|
confirmButtonColor: "#DD6B55",
|
||||||
|
html: true,
|
||||||
|
}, function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "/api/mods/delete/all",
|
||||||
|
method: "POST",
|
||||||
|
dataType: "JSON",
|
||||||
|
success: (data) => {
|
||||||
|
swal("ALL mods deleted successful", "", "success");
|
||||||
|
class_this.setState({
|
||||||
|
installedMods: data.data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: (jqXHR, status, err) => {
|
||||||
|
console.log('api/mods/delete/all', status, err.toString());
|
||||||
|
swal({
|
||||||
|
title: "Delete all mods went wrong",
|
||||||
|
text: err.toString() + "<br>" + jqXHR.responseJSON.data,
|
||||||
|
type: "error",
|
||||||
|
html: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
updateModHandler(e, toggleUpdateStatus, removeVersionAvailableStatus) {
|
updateModHandler(e, toggleUpdateStatus, removeVersionAvailableStatus) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -397,6 +439,7 @@ class ModsContent extends React.Component {
|
|||||||
submitFactorioLogin={this.handlerFactorioLogin}
|
submitFactorioLogin={this.handlerFactorioLogin}
|
||||||
toggleMod={this.toggleModHandler}
|
toggleMod={this.toggleModHandler}
|
||||||
deleteMod={this.deleteModHandler}
|
deleteMod={this.deleteModHandler}
|
||||||
|
deleteAll={this.deleteAllHandler}
|
||||||
updateMod={this.updateModHandler}
|
updateMod={this.updateModHandler}
|
||||||
uploadModSuccessHandler={this.uploadModSuccessHandler}
|
uploadModSuccessHandler={this.uploadModSuccessHandler}
|
||||||
modContentClass={this}
|
modContentClass={this}
|
||||||
|
Loading…
Reference in New Issue
Block a user