Skip to content

Commit

Permalink
Merge pull request #47 from gen0cide/dbv1
Browse files Browse the repository at this point in the history
add 3 file functions and testing new build_cli scripts for generating vm functions
  • Loading branch information
gen0cide committed Mar 10, 2018
2 parents 0e2c25b + 748f0b3 commit af06401
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 12 deletions.
52 changes: 51 additions & 1 deletion FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ Retrieves a packed asset from the VM embedded file store.



## `CreateDir(path)`

Creates a directory at a given path or return an error

### Argument List

* **path** *string*

### Returned Object Fields

* **fileError** *error*

---



## `DelRegKey(registryString, path)`

Delete a registry key
Expand Down Expand Up @@ -216,6 +232,23 @@ Executes system commands.



## `FileExists(path)`

Checks if a file exists and returns a bool

### Argument List

* **path** *string*

### Returned Object Fields

* **fileExists** *bool*
* **fileError** *error*

---



## `FindProcByName(procName)`

Returns the Pid of a given proccess, if the proccess can not be found, an error is returned
Expand Down Expand Up @@ -417,6 +450,23 @@ Generates a random alpha numeric string of a specified length.



## `ReadFile(path)`

Reads a file path and returns a byte array

### Argument List

* **path** *string*

### Returned Object Fields

* **fileBytes** *[]byte*
* **fileError** *error*

---



## `RemoveServiceByName(name)`

Uninstalls a system service
Expand Down Expand Up @@ -476,7 +526,7 @@ Starts a system service

### Returned Object Fields

* **installError** *error*
* **runtimeError** *error*

---

Expand Down
8 changes: 4 additions & 4 deletions compiler/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions engine/lib_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,141 @@ import (
// // obj.fileError
//
func (e *Engine) WriteFile(path string, fileData []byte, perms int64) (int, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
e.Logger.WithField("trace", "true").Errorf("File error: %s", err.Error())
return 0, err
}
err := ioutil.WriteFile(path, fileData, os.FileMode(uint32(perms)))
if err != nil {
e.Logger.WithField("trace", "true").Errorf("Error writing the file: %s", err.Error())
return 0, err
}
return len(fileData), nil
}

// ReadFile - Reads a file path and returns a byte array
//
// Package
//
// file
//
// Author
//
// - ahhh (https://github.com/ahhh)
//
// Javascript
//
// Here is the Javascript method signature:
// ReadFile(path)
//
// Arguments
//
// Here is a list of the arguments for the Javascript function:
// * path (string)
//
// Returns
//
// Here is a list of fields in the return object:
// * obj.fileBytes ([]byte)
// * obj.fileError (error)
//
// Example
//
// Here is an example of how to use this function in gscript:
// var obj = ReadFile(path);
// // obj.fileBytes
// // obj.fileError
//
func (e *Engine) ReadFile(path string) ([]byte, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
e.Logger.WithField("trace", "true").Errorf("File error: %s", err.Error())
return []byte{}, err
}
dat, err := ioutil.ReadFile(path)
if err != nil {
e.Logger.WithField("trace", "true").Errorf("Error writing the file: %s", err.Error())
return nil, err
}
return dat, nil
}

// FileExists - Checks if a file exists and returns a bool
//
// Package
//
// file
//
// Author
//
// - ahhh (https://github.com/ahhh)
//
// Javascript
//
// Here is the Javascript method signature:
// FileExists(path)
//
// Arguments
//
// Here is a list of the arguments for the Javascript function:
// * path (string)
//
// Returns
//
// Here is a list of fields in the return object:
// * obj.fileExists (bool)
// * obj.fileError (error)
//
// Example
//
// Here is an example of how to use this function in gscript:
// var obj = FileExists(path);
// // obj.fileExists
// // obj.fileError
//
func (e *Engine) FileExists(path string) (bool, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
e.Logger.WithField("trace", "true").Errorf("File error: %s", err.Error())
return false, err
}
return true, nil
}

// CreateDir - Creates a directory at a given path or return an error
//
// Package
//
// file
//
// Author
//
// - ahhh (https://github.com/ahhh)
//
// Javascript
//
// Here is the Javascript method signature:
// CreateDir(path)
//
// Arguments
//
// Here is a list of the arguments for the Javascript function:
// * path (string)
//
// Returns
//
// Here is a list of fields in the return object:
// * obj.fileError (error)
//
// Example
//
// Here is an example of how to use this function in gscript:
// var obj = CreateDir(path);
// // obj.fileError
//
func (e *Engine) CreateDir(path string) error {
err := os.MkdirAll(path, 0700)
if err != nil {
e.Logger.WithField("trace", "true").Errorf("Error writing the file: %s", err.Error())
return err
}
return nil
}
4 changes: 2 additions & 2 deletions engine/lib_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ func (e *Engine) InstallSystemService(path, name, displayName, description strin
// Returns
//
// Here is a list of fields in the return object:
// * obj.installError (error)
// * obj.runtimeError (error)
//
// Example
//
// Here is an example of how to use this function in gscript:
// var obj = StartServiceByName(name);
// // obj.installError
// // obj.runtimeError
//
func (e *Engine) StartServiceByName(name string) error {
c := &services.Config{
Expand Down
Loading

0 comments on commit af06401

Please sign in to comment.