Skip to content

Commit

Permalink
Changed Makefile to reference .cpp and .hpp dependencies
Browse files Browse the repository at this point in the history
Changed internal and external from .txt to .config
Added --version option
Added checks to see if the config and hosts file actually opened properly.
  • Loading branch information
tayler6000 committed Jun 26, 2022
1 parent 0d8af01 commit 947d779
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
EXE = iswitch
default: bin main.o helpers.o
g++ -o bin/$(EXE) main.o helpers.o -static
main.o:
main.o: src/main.cpp
g++ -c -o main.o src/main.cpp -static
helpers.o:
helpers.o: src/helpers.cpp src/helpers.hpp
g++ -c -o helpers.o src/helpers.cpp -static
win64: bin main.win64.o helpers.win64.o
x86_64-w64-mingw32-g++ -o bin/$(EXE).x86_64.exe main.win64.o helpers.win64.o -static
main.win64.o:
main.win64.o: src/main.cpp
x86_64-w64-mingw32-g++ -c -o main.win64.o src/main.cpp -static
helpers.win64.o:
helpers.win64.o: src/helpers.cpp src/helpers.hpp
x86_64-w64-mingw32-g++ -c -o helpers.win64.o src/helpers.cpp -static
win32: bin main.win32.o helpers.win32.o
i686-w64-mingw32-g++ -o bin/$(EXE).i686.exe main.win32.o helpers.win32.o -static
main.win32.o:
main.win32.o: src/main.cpp
i686-w64-mingw32-g++ -c -o main.win32.o src/main.cpp -static
helpers.win32.o:
helpers.win32.o: src/helpers.cpp src/helpers.hpp
i686-w64-mingw32-g++ -c -o helpers.win32.o src/helpers.cpp -static
bin:
mkdir bin
Expand All @@ -26,8 +26,8 @@ ifneq ($(shell id -u), 0)
else
cp bin/$(EXE) /etc/$(EXE)
cp /etc/hosts /etc/hosts.iswitch.backup
cp /etc/hosts /etc/internal.txt
cp /etc/hosts /etc/external.txt
cp /etc/hosts /etc/internal.config
cp /etc/hosts /etc/external.config
cp helpers/linux/iswitch.sh /bin/iswitch
endif
uninstall:
Expand Down
6 changes: 3 additions & 3 deletions helpers/windows/32-Bit_Installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ UninstPage instfiles
Section "main"
SetOutPath "C:\Windows\System32\drivers\etc"
File /oname=iswitch.exe "iswitch.i686.exe"
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\internal.txt
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\external.txt
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\internal.config
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\external.config
SetOutPath "$PROGRAMFILES\iswitch"
File "iswitch.bat"
File "PathEd.exe"
ExecWait '$PROGRAMFILES\iswitch\PathEd.exe add "$PROGRAMFILES\iswitch\\"'
Delete "$PROGRAMFILES\iswitch\PathEd.exe"
WriteUninstaller "$PROGRAMFILES\iswitch\uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayName" "iswitch (32-bit)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayVersion" "1.0.1"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayVersion" "1.1.0"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "NoModify" 0x00000001
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "NoRepair" 0x00000001
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "UninstallString" "$PROGRAMFILES\iswitch\uninstall.exe"
Expand Down
6 changes: 3 additions & 3 deletions helpers/windows/64-Bit_Installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ UninstPage instfiles
Section "main"
SetOutPath "C:\Windows\System32\drivers\etc"
File /oname=iswitch.exe "iswitch.x86_64.exe"
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\internal.txt
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\external.txt
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\internal.config
CopyFiles C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\external.config
SetOutPath "$PROGRAMFILES64\iswitch"
File "iswitch.bat"
File "PathEd.exe"
ExecWait '$PROGRAMFILES64\iswitch\PathEd.exe add "$PROGRAMFILES64\iswitch\\"'
Delete "$PROGRAMFILES64\iswitch\PathEd.exe"
WriteUninstaller "$PROGRAMFILES64\iswitch\uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayName" "iswitch (64-bit)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayVersion" "1.0.1"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "DisplayVersion" "1.1.0"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "NoModify" 0x00000001
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "NoRepair" 0x00000001
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\iswitch" "UninstallString" "$PROGRAMFILES64\iswitch\uninstall.exe"
Expand Down
29 changes: 27 additions & 2 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include "helpers.hpp"

std::string VERSION = "1.1.0";

void help(char* prompt){
std::cout << "iswitch usage:" << std::endl;
std::cout << prompt << " internal" << std::endl;
std::cout << prompt << " external" << std::endl;
std::cout << prompt << " --version" << std::endl;
std::exit(EXIT_FAILURE);
}

void internal(){
std::cout << "Switching to internal..." << std::endl;
std::ifstream internal("internal.txt");
std::ifstream internal("internal.config");
if(!internal.is_open()){
std::cout << "Unable to open internal config file!" << std::endl;
std::exit(EXIT_FAILURE);
}
std::ofstream hosts("hosts");
if(!hosts.is_open()){
std::cout << "Unable to open hosts file!" << std::endl;
std::exit(EXIT_FAILURE);
}
char temp;
while(!internal.eof()){
internal.get(temp);
Expand All @@ -25,8 +37,16 @@ void internal(){

void external(){
std::cout << "Switching to external..." << std::endl;
std::ifstream external("external.txt");
std::ifstream external("external.config");
if(!external.is_open()){
std::cout << "Unable to open external config file!" << std::endl;
std::exit(EXIT_FAILURE);
}
std::ofstream hosts("hosts");
if(!hosts.is_open()){
std::cout << "Unable to open hosts file!" << std::endl;
std::exit(EXIT_FAILURE);
}
char temp;
while(!external.eof()){
external.get(temp);
Expand All @@ -35,3 +55,8 @@ void external(){
external.close();
hosts.close();
}

void version(){
std::cout << "iswitch " << VERSION << std::endl;
std::exit(EXIT_SUCCESS);
}
5 changes: 3 additions & 2 deletions src/helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef HELP_HPP
#define HELP_HPP
#ifndef HELPERS_HPP
#define HELPERS_HPP

void help(char* prompt);
void internal();
void external();
void version();

#endif
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ int main(int cargs, char* args[]){
internal();
}else if(choice == "external"){
external();
}else if(choice == "--version"){
version();
}else{
help(args[0]);
}
Expand Down

0 comments on commit 947d779

Please sign in to comment.