diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ea2b58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# ---> Go +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.buildpath +.hgignore.swp +.project +.orig +.swp +.idea/ +.settings/ +.vscode/ +testdata/ +vender/ +bin/ +*/.DS_Store +main +.vscode +__debug_bin +history/ +release/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5181a4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 ClarkQAQ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..143ec28 --- /dev/null +++ b/README.en.md @@ -0,0 +1,38 @@ +

+

Restory

+

+ Re (store + (hi) story) VSCode History Recovery Tool +

+

+ +> Are you using VSCode and accidentally deleted your folder? Restory can help you recover it! + +### Principle + +This is a very simple tool. Restory scans the file modification history files of VSCode to obtain information, and rebuilds the directory structure and file content at the location you specify. +Unfortunately, you cannot use Restory to recover files that were not modified through VSCode, as VSCode does not generate the corresponding modification history files. + +### Usage + +Download the binary file of `restory` for your platform from the Release page and run it. + +For example, on the Linux platform: + +```bash +$ curl -L -o ./restory_linux_amd64 https://github.com/ClarkQAQ/restory/releases/latest/download/restory_linux_amd64 +$ chmod +x ./restory_linux_amd64 +$ ./restory_linux_amd64 ~/.config/Code/User/History /tmp/code-history +``` + +The VSCode history folder is usually located at `~/.config/Code/User/History` on Linux and `C:\Users\[your username]\AppData\Local\Code\User\History` on Windows. + +[Windows Download](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_windows_amd64.exe) +[Linux Download](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_linux_amd64) +[MacOS Download](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_darwin_amd64) + +### Finally + +Please remember to back up your important files regularly! Upload them to Git timely! +This tool might help you once, but it cannot guarantee to help you every time... + +--- \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d15e9b7 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +

+

Restory

+

+ Re (store + (hi) story) VSCode 历史记录文件恢复工具 +
+ VSCode History Recovery Tool +

+

+ +[English README](README.en.md) + +> 你在使用 VSCode,你的文件夹不小心删掉了? Restory 就能帮你恢复! + +### 原理 + +这是一个很简单的工具. Restory 通过扫描 VSCode 的文件修改历史文件获取信息, 并在你指定的位置重建文件夹目录结构和文件内容。 +很不幸的是, 你没有经过 VSCode 无法使用 Restore 恢复, 因为 VSCode 并没有产生对应的修改历史文件。 + + +### 使用 + +前往 Release 下载您平台对应的 `restory` 的二进制文件然后运行即可. + +例如在 Linux 平台: + +```bash +$ curl -L -o ./restory_linux_amd64 https://github.com/ClarkQAQ/restory/releases/latest/download/restory_linux_amd64 +$ chmod +x ./restory_linux_amd64 +$ ./restory_linux_amd64 ~/.config/Code/User/History /tmp/code-history +``` + +VSCode 历史文件夹目录在 Linux 平台通常是 `~/.config/Code/User/History`, Windows 平台则是 `C:\Users\[你的用户名]\AppData\Local\Code\User\History`. + +[Windows 下载链接](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_windows_amd64.exe) +[Linux 下载链接](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_linux_amd64) +[MacOS 下载链接](https://github.com/ClarkQAQ/restory/releases/latest/download/restory_darwin_amd64) + +### 最后 + +以后请多备份自己的重要文件! 及时上传到 Git! +或许我的这个工具能帮助你一次, 但是不能保证每一次都能帮助你... \ No newline at end of file diff --git a/build b/build new file mode 100755 index 0000000..436a760 --- /dev/null +++ b/build @@ -0,0 +1,38 @@ +#!/bin/bash + +# 定义平台和架构 +PLATFORMS=("darwin/amd64" "darwin/arm64" "linux/amd64" "linux/arm64" "windows/amd64" "windows/386") + +# 定义输出目录 +OUTPUT_DIR="release" + +# 创建输出目录 +mkdir -p $OUTPUT_DIR + +# 当前文件夹名称 +CURRENT_DIR=$(basename $(pwd)) + +# 编译 main.go +for PLATFORM in "${PLATFORMS[@]}" +do + # 拆分操作系统和架构 + IFS="/" read -r OS ARCH <<< "$PLATFORM" + + # 设置输出文件名 + OUTPUT_NAME="$CURRENT_DIR-$OS-$ARCH" + if [ "$OS" = "windows" ]; then + OUTPUT_NAME+=".exe" + fi + + # 设置环境变量并编译 + echo "正在编译 $OS/$ARCH..." + env GOOS=$OS GOARCH=$ARCH go build -o $OUTPUT_DIR/$OUTPUT_NAME main.go + + if [ $? -ne 0 ]; then + echo "编译 $OS/$ARCH 失败!" + else + echo "编译 $OS/$ARCH 成功:$OUTPUT_DIR/$OUTPUT_NAME" + fi +done + +echo "所有平台编译完成!" \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..100758f --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module restory + +go 1.22.4 + +replace uw => github.com/ClarkQAQ/uw v0.0.0-20240504030941-56cb77a40d8a + +require uw v0.0.0-00010101000000-000000000000 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..49055ea --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/ClarkQAQ/uw v0.0.0-20240504030941-56cb77a40d8a h1:vsK1qfNAzCdaUNYeFl/1wh1CspCkq1tmubPTgpOdx3c= +github.com/ClarkQAQ/uw v0.0.0-20240504030941-56cb77a40d8a/go.mod h1:9+F2GXZmX6j/Ix9T/6yuk77vsW3lzYg2xmyVNLy93Iw= diff --git a/main.go b/main.go new file mode 100644 index 0000000..ea2534f --- /dev/null +++ b/main.go @@ -0,0 +1,177 @@ +package main + +import ( + "encoding/json" + "errors" + "flag" + "fmt" + "io" + "io/fs" + "os" + "path/filepath" + "sort" + "strings" + "uw/ulog" +) + +type Entrie struct { + Version int `json:"version"` + Resource string `json:"resource"` + Entries EntrieObjects `json:"entries"` +} + +type EntrieObject struct { + ID string `json:"id"` + Timestamp int64 `json:"timestamp"` + Source string `json:"source,omitempty"` +} + +type EntrieObjects []EntrieObject + +func (es EntrieObjects) Len() int { + return len(es) +} + +func (es EntrieObjects) Less(i, j int) bool { + return es[i].Timestamp > es[j].Timestamp +} + +func (es EntrieObjects) Swap(i, j int) { + es[i], es[j] = es[j], es[i] +} + +func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "Welcome to Restory.\n") + fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]) + flag.PrintDefaults() + fmt.Fprintf(flag.CommandLine.Output(), "example: %s