Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
angelbests committed Nov 11, 2024
1 parent 08f3390 commit 78a23ae
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions src/functions/lnks.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Command } from '@tauri-apps/plugin-shell';
import { mkdir, readDir, readFile } from "@tauri-apps/plugin-fs";
import { appDataDir, BaseDirectory, basename, extname, homeDir, resolve } from "@tauri-apps/api/path";
const lnkPath = [
await homeDir() + "\\Desktop",
"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs",
await homeDir() + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs"
]
import { readDir } from "@tauri-apps/plugin-fs";
import { basename, extname, homeDir, resolve } from "@tauri-apps/api/path";

export const getlnks =async function(){
let lnks = [];
let lnkFiles = await getLnkFile();

// 拼接shell脚本
let lnkFilesstr = "$lnkFiles = @("
for(let i=0;i<lnkFiles.length;i++){
Expand Down Expand Up @@ -57,13 +51,26 @@ export const getlnks =async function(){

})
}
console.log(`lnks:${lnks}`)
return lnks;
}

// 获取lnk文件列表
const getLnkFile =async function(){
let lnkFiles = [];
let files = [];
const lnkPath = [
"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs",
await homeDir() + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs"
]

let desktop = await readDir(await homeDir() + "\\desktop");
for(let i=0;i<desktop.length;i++){
if(desktop[i].isFile){
files.push(await resolve(await homeDir() + "\\desktop",desktop[i].name))
}
}

for(let i=0;i<lnkPath.length;i++){
files.push(...await scanFiles(lnkPath[i]))
}
Expand All @@ -89,6 +96,7 @@ const getLnkFile =async function(){
return true
}
})
console.log(lnkFiles)
return lnkFiles;
}

Expand All @@ -110,28 +118,28 @@ const scanFiles = async function(dir:string){
}

// 使用shman 获取lnk文件的信息
export const getLnkInfo2 =async function(){
let lnks = [];
await mkdir("lnk",{"baseDir":BaseDirectory.AppData,"recursive":true})
let path = await resolve(await appDataDir(),"lnk","lnk.txt")
let res = await Command.sidecar(
"bin/shman",
[
"/stab",
path
]
).execute();
if(res.code == 0){
let unit8buffer= await readFile(path);
let txt = new TextDecoder("GBK").decode(unit8buffer)
let arr = txt.split("\r\n");
for(let i=0;i<txt.length;i++){
if(arr[i]){
let str = arr[i].split("\t")
lnks.push(
str
)
}
}
}
}
// export const getLnkInfo2 =async function(){
// let lnks = [];
// await mkdir("lnk",{"baseDir":BaseDirectory.AppData,"recursive":true})
// let path = await resolve(await appDataDir(),"lnk","lnk.txt")
// let res = await Command.sidecar(
// "bin/shman",
// [
// "/stab",
// path
// ]
// ).execute();
// if(res.code == 0){
// let unit8buffer= await readFile(path);
// let txt = new TextDecoder("GBK").decode(unit8buffer)
// let arr = txt.split("\r\n");
// for(let i=0;i<txt.length;i++){
// if(arr[i]){
// let str = arr[i].split("\t")
// lnks.push(
// str
// )
// }
// }
// }
// }

0 comments on commit 78a23ae

Please sign in to comment.