From acdb157282ac4705d8ec3ffab75b6bba2cc08550 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 5 Jul 2021 16:47:10 +0300 Subject: Changed file structure and implemented rester file creation and login check --- go-src/folderPaths/folderPaths.go | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 go-src/folderPaths/folderPaths.go (limited to 'go-src/folderPaths/folderPaths.go') diff --git a/go-src/folderPaths/folderPaths.go b/go-src/folderPaths/folderPaths.go new file mode 100644 index 0000000..67bb92b --- /dev/null +++ b/go-src/folderPaths/folderPaths.go @@ -0,0 +1,49 @@ +package folderPaths + +import ( + "os" + "runtime" +) + +func InitFolders() { + dirs := []string{rootFolder(), buildPath(rootFolder(), "Chats"), buildPath(rootFolder(), "DirectMessages"), buildPath(rootFolder(), "Users")} + for _, v := range dirs { + if _, err := os.Stat(v); os.IsNotExist(err) { + os.Mkdir(v, 0775) + } + } +} + +func FileAtChatsFolder(fileName string) string { + return buildPath(rootFolder(), "Chats", fileName+".txt") +} + +func FileAtDirectMessagesFolder(fileName string) string { + return buildPath(rootFolder(), "DirectMessages", fileName+".txt") +} + +func FileAtUsersFolder(fileName string) string { + return buildPath(rootFolder(), "Users", fileName+".txt") +} + +func rootFolder() string { + if runtime.GOOS == "windows" { + return "C:\\Users\\username\\AppData\\Roaming\\ctfc" + } + home, _ := os.UserHomeDir() + return home + "/Desktop/ctfc" +} + +func buildPath(folders ...string) (path string) { + sep := "/" + if runtime.GOOS == "windows" { + sep = "\\" + } + for i, v := range folders { + path += v + if i < len(folders)-1 { + path += sep + } + } + return +} -- cgit v1.2.3