0

I enjoy learning new ways to do things semi-automatically so if I have something I do frequently, I try to automate it for one click. I am however pretty inexperienced at it. I much prefer to be shown Why the script works rather than just having it written for me.

My current project is this:

I am trying to find a simple way to with one click update a zip directory. specifically a mod for farming simulator 19 I currently download as a zip from github, which is updated every couple days.

the steps I think I need to follow are to: 1. Obtain new release (think i have this one working) 2. zip new release (kindof working but not quite right) 3. overwrite existing zip with new one (if i can fix my current method of doing step2 it does this automatically) 4.(optional) launch game after all files are finished saving

I have been working on this for a couple days between digging through other peoples questions, and doing trial and error of bits of code.

1: I have found that I can download it automatically by way of cmd.exe using the following:

git clone https://github.com/Courseplay/courseplay.git C:\Users\*****\Documents\courseplay

From what I have read I am uncertain if this is what I want though. is the result of this command the same thing as I would get from 'download .zip'

2, 3: I learned that I can then zip, and overwrite the existing file by way of powershell with:

Compress-Archive -Force -Path "C:\Users\*****\Documents\courseplay" -DestinationPath "C:\Users\*****\Documents\My Games\FarmingSimulator2019\mods\courseplay.zip"

However this isn't working as I hoped/expected as it is adding the folder to a zip rather than just zipping its contents...

to clarify i am looking for:

Courseplay.zip --some files

I am getting

Courseplay.zip --Courseplay ----some files

Furthermore, I have not been able to combine them into one item. I cant use the git command from powershell, and I cant seem to create or interact with files in a zipped folder from cmd. I tried using powershell to pass to cmd a couple of ways I saw in Running CMD command in PowerShell

cmd.exe "git clone https://github.com/Courseplay/courseplay.git c:\Users\*****\Documents\courseplay"

Which outputs

'ourseplay' is not recognized as an internal or external command, operable program or batch file.

cmd.exe /c "git clone https://github.com/Courseplay/courseplay.git c:\Users\*****\Documents\courseplay"

Which outputs

'git' is not recognized as an internal or external command, operable program or batch file.

"git clone https://github.com/Courseplay/courseplay.git c:\Users\*****\Documents\courseplay
" | cmd.exe

Which outputs

Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\*****\Documents>git clone https://github.com/Courseplay/courseplay.git c:\Users\*****\Documents\courseplay
Cloning into 'c:\Users\*****\Documents\courseplay'...
fatal: unable to access 'https://github.com/Courseplay/courseplay.git/': Could not resolve host: github.com

So my primary issues are: How to zip the contents of a folder where my current method is creating a zip with the original folder as a subfolder

and

I currently must use two different tools to do this. Is there a way i can script it to do all of the above with one doubleclick.

I have not really looked into launching the game as part of the script yet, as i am still struggling with getting the rest of it working and it was an afterthought. I do know in cmd

start steam://rungameid/787860 will launch it.

I would be fine with cmd, powershell, or some other form of scripting that is able to accomplish all of the above.

Additionally is something needed to tell it to wait between steps. (does it by default wait for completion of the download from git clone before it moves to the next step, or does it have to be told to wait while the download finishes)

2 Answers2

0

Github provides a simple api to download a zip archive. See this answer.

curl -LOk https://github.com/Courseplay/courseplay/archive/master.zip

To use curl in cmd, see this answer.

Other hosting services may also have similar methods. Generally, to create a zip archive of a revision, master for example, from a remote repository, you can run

git archive --remote=<repository_url> master -o foo.zip

Some hosting services may reject git archive.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0

Github provides a simple api to download a zip archive. See this answer.

curl -LOk https://github.com/Courseplay/courseplay/archive/master.zip

ElpieKay

This info seemed to be run in cmd (I think) from the article you posted, but it gave me the bit I needed. Unlike my attempt to clone, it also worked piped to cmd.exe from powershell which allows the entire script to be in one file.

I also decided to set up a folder junction via mklink to be able to sync my saves and mod folders across all the computers I use through onedrive.

My final code looks like this.

cd C:\Users\username\OneDrive
"curl -LOk https://github.com/Courseplay/courseplay/archive/master.zip" | cmd.exe
Expand-Archive C:\Users\username\OneDrive\master.zip
Compress-Archive C:\Users\username\OneDrive\master\courseplay-master\* C:\Users\username\OneDrive\FarmingSimulator2019\mods\courseplay.zip -force
Remove-Item –path C:\Users\username\OneDrive\master.zip –recurse -force
Remove-Item –path C:\Users\username\OneDrive\master –recurse -force
start steam://rungameid/787860

which, as I was trying to do, gives me one desktop item to update courseplay, unzip the downloaded file, rezip the desired subfolder, rename it and overwrite existing zip. furthermore it now also deletes the downloaded zip and extracted folder to clean up after itself, and launches the game. Thank You @ElpieKay for providing the piece i needed to finish it off.

Community
  • 1
  • 1
  • I thought I had it figured out, and while it does zip it, the compression seems off somehow, preventing it from running correctly. I have tried -CompressionLevel with NoCompression, optimal and fastest. When running the game It causes errors which result in an endless load screen. – admini.Strader May 11 '19 at 02:38
  • 7zip shows that the uncompressed size is 4,858,608 (4.8MB) The manually processed (unzip, and manually repackage the courseplay-master folder) is 859 KB (879,928 bytes) -compressionlevel nocompression gives 4.65 MB (4,876,909 bytes) optimal yields 876 KB (897,634 bytes) fastest yields 1.00 MB (1,053,425 bytes) No method other than manually zipping them lets it run when loaded from the game. Does anyone have other thoughts? – admini.Strader May 11 '19 at 03:43