Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
60f65871
There was an error fetching the commit references. Please try again later.
Unverified
Commit
60f65871
authored
2 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
fix: reduce unwrap
parent
a9bf3291
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src-tauri/src/utils/init.rs
+16
-16
16 additions, 16 deletions
src-tauri/src/utils/init.rs
with
16 additions
and
16 deletions
src-tauri/src/utils/init.rs
+
16
−
16
View file @
60f65871
use
crate
::
utils
::{
dirs
,
tmpl
};
use
anyhow
::
Result
;
use
chrono
::
Local
;
use
log
::
LevelFilter
;
use
log4rs
::
append
::
console
::
ConsoleAppender
;
...
...
@@ -11,7 +12,7 @@ use std::path::PathBuf;
use
tauri
::
PackageInfo
;
/// initialize this instance's log file
fn
init_log
(
log_dir
:
&
PathBuf
)
{
fn
init_log
(
log_dir
:
&
PathBuf
)
->
Result
<
()
>
{
let
local_time
=
Local
::
now
()
.format
(
"%Y-%m-%d-%H%M%S"
)
.to_string
();
let
log_file
=
format!
(
"{}.log"
,
local_time
);
let
log_file
=
log_dir
.join
(
log_file
);
...
...
@@ -22,8 +23,7 @@ fn init_log(log_dir: &PathBuf) {
.build
();
let
tofile
=
FileAppender
::
builder
()
.encoder
(
Box
::
new
(
PatternEncoder
::
new
(
time_format
)))
.build
(
log_file
)
.unwrap
();
.build
(
log_file
)
?
;
let
config
=
Config
::
builder
()
.appender
(
Appender
::
builder
()
.build
(
"stdout"
,
Box
::
new
(
stdout
)))
...
...
@@ -34,14 +34,15 @@ fn init_log(log_dir: &PathBuf) {
.additive
(
false
)
.build
(
"app"
,
LevelFilter
::
Info
),
)
.build
(
Root
::
builder
()
.appender
(
"stdout"
)
.build
(
LevelFilter
::
Info
))
.unwrap
();
.build
(
Root
::
builder
()
.appender
(
"stdout"
)
.build
(
LevelFilter
::
Info
))
?
;
log4rs
::
init_config
(
config
)
.unwrap
();
log4rs
::
init_config
(
config
)
?
;
Ok
(())
}
/// Initialize all the files from resources
fn
init_config
(
app_dir
:
&
PathBuf
)
->
std
::
io
::
Result
<
()
>
{
fn
init_config
(
app_dir
:
&
PathBuf
)
->
Result
<
()
>
{
// target path
let
clash_path
=
app_dir
.join
(
"config.yaml"
);
let
verge_path
=
app_dir
.join
(
"verge.yaml"
);
...
...
@@ -69,25 +70,24 @@ pub fn init_app(package_info: &PackageInfo) {
let
res_dir
=
dirs
::
app_resources_dir
(
package_info
);
if
!
app_dir
.exists
()
{
fs
::
create_dir_all
(
&
app_dir
)
.unwrap
()
;
let
_
=
fs
::
create_dir_all
(
&
app_dir
);
}
if
!
log_dir
.exists
()
{
fs
::
create_dir_all
(
&
log_dir
)
.unwrap
()
;
let
_
=
fs
::
create_dir_all
(
&
log_dir
);
}
if
!
profiles_dir
.exists
()
{
fs
::
create_dir_all
(
&
profiles_dir
)
.unwrap
()
;
let
_
=
fs
::
create_dir_all
(
&
profiles_dir
);
}
init_log
(
&
log_dir
);
if
let
Err
(
err
)
=
init_config
(
&
app_dir
)
{
log
::
error!
(
target
:
"app"
,
"{err}"
);
}
crate
::
log_if_err!
(
init_log
(
&
log_dir
));
crate
::
log_if_err!
(
init_config
(
&
app_dir
));
// copy the resource file
let
mmdb_path
=
app_dir
.join
(
"Country.mmdb"
);
let
mmdb_tmpl
=
res_dir
.join
(
"Country.mmdb"
);
if
!
mmdb_path
.exists
()
&&
mmdb_tmpl
.exists
()
{
fs
::
copy
(
mmdb_tmpl
,
mmdb_path
)
.unwrap
()
;
let
_
=
fs
::
copy
(
mmdb_tmpl
,
mmdb_path
);
}
// copy the wintun.dll
...
...
@@ -96,7 +96,7 @@ pub fn init_app(package_info: &PackageInfo) {
let
wintun_path
=
app_dir
.join
(
"wintun.dll"
);
let
wintun_tmpl
=
res_dir
.join
(
"wintun.dll"
);
if
!
wintun_path
.exists
()
&&
wintun_tmpl
.exists
()
{
fs
::
copy
(
wintun_tmpl
,
wintun_path
)
.unwrap
()
;
let
_
=
fs
::
copy
(
wintun_tmpl
,
wintun_path
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment